tagged [dbcontext]

Type or namespace name Mock<> could not be found Entity Framework 6

Type or namespace name Mock could not be found Entity Framework 6 I am trying to mock my `DbContext` for writing my unit tests. I saw a tutorial, and tried to do it like the following: But I am gettin...

EF 4.1 OnModelCreating not called

EF 4.1 OnModelCreating not called I have a problem with EF 4.1 not calling `OnModelCreating` so that I can configure tables etc. I have an existing database. Here is my connection string: ```

25 Jul at 15:59

Mocking EF DbContext with Moq

Mocking EF DbContext with Moq I'm trying to create a unit test for my service with a mocked DbContext. I created an interface `IDbContext` with the following functions: My real context implements this...

How can I log all entities change, during .SaveChanges() using EF code first?

How can I log all entities change, during .SaveChanges() using EF code first? I'm using . I'm using a base Repository for all my repositories and an `IUnitofWork` that inject to the repositories, too:...

How to Moq Entity Framework SqlQuery calls

How to Moq Entity Framework SqlQuery calls I've been able to mock `DbSet`'s from entity framework with Moq using this [link](http://msdn.microsoft.com/en-gb/data/dn314429.aspx). However, I would now l...

24 Sep at 10:48

Can you get the DbContext from a DbSet?

Can you get the DbContext from a DbSet? In my application it is sometimes necessary to save 10,000 or more rows to the database in one operation. I've found that simply iterating and adding each item ...

LINQ to Entities only supports casting EDM primitive or enumeration types with IEntity interface

LINQ to Entities only supports casting EDM primitive or enumeration types with IEntity interface I have the following generic extension method: ``` public static T GetById(this IQueryable collection, ...

How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer?

How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer? I'm using the DbContext and Code First APIs introduced with Entity Framework 4.1. The uses basic data types s...

How do you configure the DbContext when creating Migrations in Entity Framework Core?

How do you configure the DbContext when creating Migrations in Entity Framework Core? Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration comm...

c# entity framework: correct use of DBContext class inside your repository class

c# entity framework: correct use of DBContext class inside your repository class I used to implement my repository classes as you can see below ``` public Class MyRepository { private MyDbContext _...

9 Oct at 14:48

DbContext won't keep connection open for re-use

DbContext won't keep connection open for re-use I'm trying to reuse an existing database connection so that I can do multiple database operations using a `TransactionScope` without invoking MSDTC. Ent...

DBContext disposing doesn't change the number of opened connections

DBContext disposing doesn't change the number of opened connections In highload legacy application I've found tons of code which just creates new DBContext, then makes request and doesn't dispose the ...

How to extend DbContext with partial class and partial OnModelCreating method in EntityFramework Core

How to extend DbContext with partial class and partial OnModelCreating method in EntityFramework Core I'm using EF Core and DatabaseFirst approach. My dbContext is created automatically by `Scaffold-D...

EF Core / DbContext > Map custom type as primary key

EF Core / DbContext > Map custom type as primary key Using EF Core I'm trying to build a model for the follow entity.

Entity Framework code first: How to ignore classes

Entity Framework code first: How to ignore classes This is similar to questions [here](https://stackoverflow.com/questions/7886672/how-to-ignore-entity-in-entity-framework-code-first-via-setup) and [h...

23 May at 11:55

What do I need to add into OnModelCreating(DbModelBuilder modelBuilder) function to define relations between Person and Role?

What do I need to add into OnModelCreating(DbModelBuilder modelBuilder) function to define relations between Person and Role? I'm using EntityFramework version 5.0 in WinForms project, .net 4.5. I hav...

Getting "The entity type <model> is not part of the model for the current context."

Getting "The entity type is not part of the model for the current context." I am having this issue updating my database 1 column at a time in asp.net using web api. I am trying to query a PUT to just ...

Configure multiple database Entity Framework 6

Configure multiple database Entity Framework 6 In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third...

Refreshing Sql Connection Azure AD access token inside long-lived Entity Framework Context

Refreshing Sql Connection Azure AD access token inside long-lived Entity Framework Context I'm trying to set up a few .NET applications to use certificate-based authentication to Azure Active Director...

The entity type <type> is not part of the model for the current context

The entity type is not part of the model for the current context I am getting into the Entity Framework, but I am unsure if I am missing a critical point in the code-first approach. I am using a gener...

EF (entity framework) usage of "using" statement

EF (entity framework) usage of "using" statement I have a project on MVC. We chose EF for our DB transactions. We created some managers for the BLL layer. I found a lot of examples, where "`using`" st...

More than one DbContext was found

More than one DbContext was found I am implementing a code first database using AspCore 2. I have a "DataContext.cs" that goes like this: ``` public class ApplicationUser : IdentityUser { public str...

The operation cannot be completed because the DbContext has been disposed using MVC 4

The operation cannot be completed because the DbContext has been disposed using MVC 4 I know that this Question is asked so many times. I have read and implemented all solution but didn't get success....

Can I clone an IQueryable to run on a DbSet for another DbContext?

Can I clone an IQueryable to run on a DbSet for another DbContext? Suppose I have built up, through some conditional logic over many steps, an `IQueryable` instance we'll call `query`. I want to get a...

Correct use of Microsoft.AspNet.Identity 2.0

Correct use of Microsoft.AspNet.Identity 2.0 I'm lost using the authentication method that comes with MVC 5 Template. I had the need to include the CreateBy user in an entity called client, so after s...