ef-code-first

How to force EF Code First to query the database?

时光怂恿深爱的人放手 提交于 2019-12-18 04:53:09
问题 I have a site managing a collection of rules and a separate Windows form application making file level changes based on the rules in the database. Both of these applications use the same libraries for a EF Code First DbContext, but each application is instantiating their own copy of the context. The problem is, each running version of the context is unaware of the changes made by the other version. E.g. If I change a rule on the site, the forms app still has the previous version. I'm aware I

How can I disable the use of the __MigrationHistory table in Entity Framework 4.3 Code First?

扶醉桌前 提交于 2019-12-18 04:45:45
问题 I'm using Entity Framework 4.3 Code First with a custom database initializer like this: public class MyContext : DbContext { public MyContext() { Database.SetInitializer(new MyContextInitializer()); } } public class MyContextInitializer : CreateDatabaseIfNotExists<MyContext> { protected override void Seed(MyContext context) { // Add defaults to certain tables in the database base.Seed(context); } } Whenever my model changes, I edit my POCO's and mappings manually and I update my database

WebApi with EF Code First generates error when having parent child relation

拟墨画扇 提交于 2019-12-18 04:42:34
问题 I am breaking my head over this issue. I did find something on the internet about it, but not a clear answer. My problem: I have to classes in Model section of an MVC3 web app: ParentClass and ChildClass On ParentClass there is a property Children of type List I used EF Code First, which neatly generates a parent table and a child table for me in the database. Now I need a REST service that gives back a List or a single ParentClass. When I remove the property Children from the ParentClass

WebApi with EF Code First generates error when having parent child relation

大憨熊 提交于 2019-12-18 04:42:06
问题 I am breaking my head over this issue. I did find something on the internet about it, but not a clear answer. My problem: I have to classes in Model section of an MVC3 web app: ParentClass and ChildClass On ParentClass there is a property Children of type List I used EF Code First, which neatly generates a parent table and a child table for me in the database. Now I need a REST service that gives back a List or a single ParentClass. When I remove the property Children from the ParentClass

EntityFramework - Where is the connection string?

China☆狼群 提交于 2019-12-18 04:31:40
问题 I've deleted the connection string from my web.config and Entity Framework is still connecting to the database! Where is the connection string being set? This is an issue because I need to make the live version of my website point to the live database. 回答1: Here's a gotcha I found with the "convention over configuration" philosophy when it comes to trying to connect to existing databases (like you're doing). If your DbContext class (e.g. Northwind) is in a namespace (e.g. MvcProject), for

LINQ to Entities does not recognize the method

纵然是瞬间 提交于 2019-12-18 04:16:08
问题 I am following this article on MSDN. I ported it to EF Code First. public interface IUnitOfWork { IRepository<Employee> Employees { get; } IRepository<TimeCard> TimeCards { get; } void Commit(); } public class HrContext : DbContext { public DbSet<Employee> Employees { get; set; } public DbSet<TimeCard> TimeCards { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Employee>() .HasMany(e => e.TimeCards) .WithOptional(tc => tc.Employee); } }

Updating a reference to a child object in Entity framework 4.1 (CodeFirst)

夙愿已清 提交于 2019-12-18 03:34:20
问题 I'm trying to update an object that I have previously saved with EntityFramework 4.1 (CodeFirst) The class Job has the following properties ... public class Job { [key] public int Id { get; set; } public string Title { get; set; } public Project Project { get; set; } public JobType JobType { get; set; } public string Description { get; set; } } The initial create works fine, but the update only commits changes to the strings.. If I change the child objects eg the JobType Property from

AutoMapper throwing StackOverflowException when calling ProjectTo<T>() on IQueryable

杀马特。学长 韩版系。学妹 提交于 2019-12-18 03:06:20
问题 I have created classes using EF Code First that have collections of each other. Entities: public class Field { public int Id { get; set; } public string Name { get; set; } public virtual List<AppUser> Teachers { get; set; } public Field() { Teachers = new List<AppUser>(); } } public class AppUser { public int Id { get; set; } public string Email { get; set; } public string Password { get; set; } public string UserName => Email; public virtual List<Field> Fields { get; set; } public AppUser()

Entity Framework: Tracking changes to FK associations

送分小仙女□ 提交于 2019-12-18 01:21:36
问题 I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title

Entity Framework: Tracking changes to FK associations

Deadly 提交于 2019-12-18 01:21:32
问题 I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title