尝试设置基于Dapper的数据访问层. ABP.Dapper文档令人困惑且不完整 [英] Trying to set up a Dapper-based Data Access Layer. ABP.Dapper documentation is confusing and incomplete

查看:724
本文介绍了尝试设置基于Dapper的数据访问层. ABP.Dapper文档令人困惑且不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个简单的DAL,该DAL将返回键入对象的列表.相当标准的数据存储库内容.我从GitHub下载了所有ABP代码,为​​Abp.Dapper和Abp.EntityFrameworkCore构建了DLL,然后按照此页面上的说明进行操作: https://aspnetboilerplate.com/Pages/Documents/Dapper-Integration

I'm trying to set up a simple DAL that will return a List of typed objects. Pretty standard data repository stuff. I downloaded all of ABP's code from GitHub, built the DLLs for Abp.Dapper and Abp.EntityFrameworkCore and started following the instructions on this page: https://aspnetboilerplate.com/Pages/Documents/Dapper-Integration

但是我什至无法超越其中的第一步.该代码无法编译,因为它不知道什么是SampleApplicationModule.但是这些说明中没有关于应该是什么的指导.

But I can't even get past step one of this. This code doesn't compile because it doesn't know what SampleApplicationModule is. But there's no guidance in these instructions as to what that is supposed to be.

我应该如何使用Abp的库?我迷路了.有人可以让我知道将数据库连接到Abp的库并查询键入对象列表所需要做的最少工作吗?

How am I supposed to use Abp's libraries? I'm lost. Can someone please let me know the minimum number of things I need to do in order to wire up my database to Abp's library and query for a List of typed objects?

Abp的Dapper集成文档中的代码:

Code from Abp's Dapper Integration documentation:

[DependsOn(
     typeof(AbpEntityFrameworkCoreModule),
     typeof(AbpDapperModule)
)]
public class MyModule : AbpModule
{
    public override void Initialize()
    {
               IocManager.RegisterAssemblyByConvention(typeof(SampleApplicationModule).GetAssembly());
    }
}

推荐答案

如果您对SampleApplicationModule的内容感到困惑,请使用以下代码

if you are confused what to write for SampleApplicationModule use the below code

模块注册

 [DependsOn(
     typeof(AbpEntityFrameworkModule),
     typeof(AbpKernelModule),
     typeof(AbpDapperModule)
 )]
 public class SampleApplicationModule : AbpModule
 {
     public override void Initialize()
     {
         IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
     }
 }

用法

public class SomeDomainService : ITransientDependency
{
    private readonly IDapperRepository<Animal> _animalDapperRepository;
    private readonly IRepository<Animal> _animalRepository;
    private readonly IDapperRepository<Person> _personDapperRepository;
    private readonly IRepository<Person> _personRepository;
    private readonly IUnitOfWorkManager _unitOfWorkManager;

    public SomeDomainService(
        IUnitOfWorkManager unitOfWorkManager,
        IRepository<Person> personRepository,
        IRepository<Animal> animalRepository,
        IDapperRepository<Person> personDapperRepository,
        IDapperRepository<Animal> animalDapperRepository)
    {
        _unitOfWorkManager = unitOfWorkManager;
        _personRepository = personRepository;
        _animalRepository = animalRepository;
        _personDapperRepository = personDapperRepository;
        _animalDapperRepository = animalDapperRepository;
    }

    public void DoSomeStuff()
    {
        using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
        {
            _personRepository.Insert(new Person("Oğuzhan"));
            _personRepository.Insert(new Person("Bread"));

            _animalRepository.Insert(new Animal("Bird"));
            _animalRepository.Insert(new Animal("Cat"));

            _unitOfWorkManager.Current.SaveChanges();

            Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Bird");

            Person person = _personDapperRepository.Get(1);
            int personCount = _personDapperRepository.Count(x => x.Name == "Oğuzhan");
            List<Animal> persons = _animalDapperRepository.GetList(x => x.Name.StartsWith("O")).ToList();

            uow.Complete();
        }
    }
}

请参阅AbpDapper的相关文章 https://github.com/aspnetboilerplate/aspnetboilerplate/pull/1854#issuecomment- 284511423

See the related post for AbpDapper https://github.com/aspnetboilerplate/aspnetboilerplate/pull/1854#issuecomment-284511423

PS:Abp.Dapper集成由社区实现.

这篇关于尝试设置基于Dapper的数据访问层. ABP.Dapper文档令人困惑且不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆