dbcontext

Entity Framework mocking requires global context

烂漫一生 提交于 2019-12-13 04:27:43
问题 I have recently began to dig into Entity Framework unit-testing with Entity Framework 6 mocking. I have noticed the following thing: Entity Framework mocking forces me to create a global context in my BL class, for example: public class RefundRepayment : IDisposable { protected DbContext _dbContext = new DbContext(); /* more properties and class code */ public void Dispose() { _dbContext.Dispose(); } } I can't quite figure it out, as I'd rather implement the using statement in every method in

MVC dbContext find parent record when current record has no elements

ε祈祈猫儿з 提交于 2019-12-13 04:06:01
问题 I'm a MVC/C# beginner so go easy. I have an existing database where a Customer has zero or many Projects. I've built an ASP.Net project from ADODB Entity data model and dbContext code generators. I have a customer: Joe Bloggs (ID=7). I click on the 'Projects' link for Joe Bloggs in my form to see his projects. He doesn't have any. I want to create a project for him so I call the Create action on the project controller. I need to pass Joe Bloggs ID to the Create action for three reasons (which

How should I setup my repositories to use the same context?

非 Y 不嫁゛ 提交于 2019-12-13 03:35:03
问题 In my LabelService I'm trying to join records from the OrderLineRepository with the LabelRepository. When I do this I get this error: The specified LINQ expression contains references to queries that are associated with different contexts. What would be the best solution for this problem? Any suggestions would be appreciated. Here is the code for my two repositories: public class LabelRepository : ILabelRepository { private OrderContext _context; public LabelRepository(string connectionName)

passed dbcontext connection string to DALayer

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:59:11
问题 I have 4 layer in my application UI , DomainClass , Model(DBCntext) , Repository . In repository i have an abstract class like this : public abstract class GenericRepository<C, T> : IGenericRepository<T> where T : class where C : DbContext, new() { private C _entities = new C(); public C Context { get { return _entities; } set { _entities = value; } } public virtual IQueryable<T> GetAll() { IQueryable<T> query = _entities.Set<T>(); return query; } public IQueryable<T> FindBy(System.Linq

Explicit Loading of child navigation properties with criteria

百般思念 提交于 2019-12-12 21:16:06
问题 Using DBContext in EF5 - after filtering and partial loading based on criteria like a date range. I'm trying to produce a complete graph or tree of objects - Persons->Events where the only Events that are included are within a date range. All this whilst preserving the standard change tracking that one gets with the following: Dim Repository As Models.personRepository = New Models.personRepository Private Sub LoadData() Dim personViewModelViewSource As System.Windows.Data.CollectionViewSource

Weird race conditions when I send high-frequency requests to my datacontext using EF (and WebAPI)

我是研究僧i 提交于 2019-12-12 20:32:36
问题 In my WebAPI controller I have this: [HttpDelete] public HttpResponseMessage DeleteFolder(int id) { _service.DeleteFolder(id); return Request.CreateResponse(HttpStatusCode.OK, "Deleted"); } _service is a db access service using _db - an instance of my project's DbContext, defined once in the constructor of the service class. In my client, I used a for loop to send a bunch of asynchronous AJAX calls to the delete method, attempting to delete multiple folders in succession. That's when stuff

How to force only one transaction within multiple DbContext classes?

可紊 提交于 2019-12-12 17:58:28
问题 Background: From another question here at SO I have a Winforms solution (Finance) with many projects (fixed projects for the solution). Now one of my customers asked me to "upgrade" the solution and add projects/modules that will come from another Winforms solution (HR). I really don't want to keep these projects as fixed projects on the existing finance solution. For that I'm trying to create plugins that will load GUI, business logic and the data layer all using MEF. Question: I have a

Using StoreGeneratedPattern.Identity with database-trigger-generated primarykey values not possible?

血红的双手。 提交于 2019-12-12 15:43:30
问题 This question is related to another question i asked here ( Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value? ) and should simply clarify, if my assumptions, regarding the problem stated in the topic, are right or not. The Problem (in detail): I want to use EF (4.1) to access a database, that already exists the database has some restrictions regarding the generation of primary key values for its tables (there is a UDF that takes a tablename and

why when i want use EF Power tools for view my model i get error?

天涯浪子 提交于 2019-12-12 12:51:40
问题 Im using EF Code first and i generate my model by "EF 4.x DbContext Fluent Generator for c#" extension in vs2010. but when i want to view my Entity model via EF Power tools i get this error:"Sequence Contains no matching element". is there any idea? 回答1: It's a bit too late and not sure if this would help but for others and historic reasons... I had the same issue (with Beta 3 - and .NET 4/2010/EF5 etc.) - the solution was relatively simple. I just moved out the project from the 'solution

Lazy Loading Not Working After SaveChanges Entity Framework

人走茶凉 提交于 2019-12-12 08:54:03
问题 In the function below, after the context.SaveChanges(), the entity PropertyType is always null. I just converted from using ObjectContext to DBContext (with database first) and before the change, it worked fine and now it doesn't. Is there something I'm missing? I check the PropertyTypeID and it is written correctly and exists in the db. All relationships are correctly setup in the db and edmx file. The generated .tt files show the PropertyType object as virtual. This is EF 5. Here is the