dbcontext

The entity type is not part of the model, EF 5

不打扰是莪最后的温柔 提交于 2019-12-30 08:42:15
问题 I am trying to update my repository to EF5 but have encountered a few errors. I've taken a look around stackoverflow for similar errors discovered a few questions/answers but unfortunately the same answers didn't resolve my issue. This is my error: The entity type User is not part of the model for the current context. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it

The entity type is not part of the model, EF 5

▼魔方 西西 提交于 2019-12-30 08:42:05
问题 I am trying to update my repository to EF5 but have encountered a few errors. I've taken a look around stackoverflow for similar errors discovered a few questions/answers but unfortunately the same answers didn't resolve my issue. This is my error: The entity type User is not part of the model for the current context. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it

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

ぐ巨炮叔叔 提交于 2019-12-28 22:29:52
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()

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

自作多情 提交于 2019-12-28 22:29:27
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()

Entity Framework Find vs. Where

天涯浪子 提交于 2019-12-28 05:31:25
问题 Is there a significant difference between .Find(id) and .Where(x = >x.Id == id) that should compel me to use .Find() over .Where()/.First() ? I would imagine that .Find() would be more efficient but is it so much more efficient that I should avoid .Where()/.First() ? The reason I ask is that I am using a generic FakeDbSet in my tests to make it easy to implement fake results and so far I have found that I must inherit that class and provide a custom implementation of .Find() whereas if I

Why re-initiate the DbContext when using the Entity Framework?

北慕城南 提交于 2019-12-27 19:13:06
问题 I don't know if there is a better way to use the DbContext because it is not recommended to set is as static when working with WCF . So we are creating it each time we want to access the database. Knowing all the advantages of using Entity Framework, some become useless since we are recreating the DbContext each time; and more may cause overhead since the process of creating big entity models is to be considered. What is your opinion? 回答1: Managing Lifetime You're correct that a single static

Why re-initiate the DbContext when using the Entity Framework?

☆樱花仙子☆ 提交于 2019-12-27 19:12:59
问题 I don't know if there is a better way to use the DbContext because it is not recommended to set is as static when working with WCF . So we are creating it each time we want to access the database. Knowing all the advantages of using Entity Framework, some become useless since we are recreating the DbContext each time; and more may cause overhead since the process of creating big entity models is to be considered. What is your opinion? 回答1: Managing Lifetime You're correct that a single static

One database, two applications, two dbContext

我怕爱的太早我们不能终老 提交于 2019-12-25 09:17:43
问题 My colleague and me developed a software, divided in two parts. The first is a WPF program while the second is a windows service. Both of them work on the same database and have their entity framework context. It works, but now I have to add a new feature giving us some troubles. I get the addedEntities to do some stuff on it before the saveChanges: var addedEntities = Entities.dbContext.ChangeTracker.Entries().Where(x => x.State == EntityState.Added && x.Entity.GetType().Name == "mytable")

The SqlParameter is already contained by another SqlParameterCollection

﹥>﹥吖頭↗ 提交于 2019-12-25 07:35:48
问题 I'm using EF DbContext SqlQuery to get a list of paged objects using PagedList (https://github.com/TroyGoode/PagedList) and I'm getting the following error: "The SqlParameter is already contained by another SqlParameterCollection" Here's my repository code: var db = (DbContext)DataContext; const string sqlString = @" WITH UserFollowerList AS ( SELECT uf.FollowId FROM UserFollow uf WHERE uf.UserId = @UserId ) SELECT * FROM UserFollowerList uf INNER JOIN [User] u ON uf.FollowId = u.UserId WHERE

DbContext declaration - Framework 4.1 - MVC 3.0

别说谁变了你拦得住时间么 提交于 2019-12-25 04:06:59
问题 Is it correct to declare a global variable of "DBContext" in a controller and then use it for all database operations? Example: public class ProductController : Controller { private readonly DBContextEntities _db = new DBContextEntities(); public ActionResult Index() { var products = _db.Products.ToList(); return View(products); } public ActionResult Create() { _db.Products.AddObject(new Product{Name="x",Price="5.2"}); _db.SaveChanges(); return View(products); } } Please Advice, 回答1: I have