简体   繁体   中英

Is it possible to use Linqpad with a Repository and UnitOfWork pattern?

In my controllers, I initialize my unit of work and repository patterns as follows:

    private readonly IUnitOfWork _unitOfWork;
    private readonly IRepository<Website> _repository;

    public ProjectsController() { }

    public ProjectsController(IUnitOfWork unitOfWorkAsync,
        IRepository<Website> repository)
    {
        _unitOfWork = unitOfWorkAsync;
        _repository = repository;
    }

And my basic usage is as follows:

                    var website = _repository
                        .Query()
                        .Select()
                        .Single(u => u.UserId == userId && u.WebsiteGuid == websiteGuid);

I would like to use Linqpad to test out the queries, and would like to know if and how to use Linqpad to do this.

I first make a connection to the db context, then connect to the Repository.dll to avoid the following errors:

The type 'Repository.Pattern.DataContext.IDataContextAsync' is defined in an assembly that is not referenced. You must add a reference to assembly 'Repository.Pattern, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. (Press F4)

The type 'Repository.Pattern.DataContext.IDataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Repository.Pattern, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

So now that everything is connected, I'm at a loss on how to proceed.

I'm making some assumptions here, such as your repository has a dependency on the DBContext connection you created. So it should just be a matter of initializing an instance:

var userId = new Guid("...");
var websiteGuid = new Guid("...");
var _repository = new Repository<Website>(this);

var website = _repository
.Query()
.Select()
.Single(u => u.UserId == userId && u.WebsiteGuid == websiteGuid);

website
.Dump();

Thanks to Sorax's tip, instead of using C# statement(s), I changed the language to C# program.

I added a reference to Repository.Pattern.Ef6\\bin\\Repository.Pattern.Ef6.dll and wrote a basic working query as follows:

void Main()
{
     //IRepository<Website> _repository =  ;

    var _repository = new Repository.Pattern.Ef6.Repository<Website>(this);

    var website = _repository
        .Query()
        .Select();

    website.Dump("The Oputput...");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM