entity-framework-5

Add new table to EF

眉间皱痕 提交于 2020-01-03 01:46:08
问题 I have a project in MVC4 (VS 2012) with Entity Framework. I have created a model by connecting to SQL Server 2008. Works great. Now I want to add one or more tables to the model. Here's what I did: opened the .edmx file. Right clicked and selected Update model from the database. Under the Add tab, it shows Tables, Views and Stored Procedure. But none of them is selectable. Am I missing something here? 回答1: Murali, if I understood well, the problem is that you didn't make changes to the

Cloning Object with many-to-many relationship in EntityFramework

允我心安 提交于 2020-01-02 19:12:55
问题 All I want is just to create an exact copy of an object. I have a class [Serializable] public class Project { public int Id { get; set; } public String Name { get; set; } //navigational fields.. public virtual List<BusinessRequirement> BusinessRequirements { get; set; } } and another [Serializable] public class BusinessRequirement { public int Id { get; set; } public String Name { get; set; } public String Description { get; set; } public virtual List<Project> Projects { get; set; } } so

EntityFramework t4 template - XML documentation

僤鯓⒐⒋嵵緔 提交于 2020-01-02 17:33:30
问题 I have the following problem with my EDMX file. In it I have written some Documentation for the properties as well as the Entities, but the t4 template of my EF 5 doesnt generate those values. My desired result should be public class Person { /// <summary> /// Hello World Summary!! /// </summary> /// <remarks> /// Hello World Remarks!! /// </remarks> public string Name { get; set; } } But I only get public class Person { public string Name { get; set; } } And if not for this, why would I else

entity framework plural table names

爷,独闯天下 提交于 2020-01-02 10:09:45
问题 I am trying to get EF 5 to generate singular table names. I have the following code in my DbContext... public partial class LiveoModelContainer : DbContext { protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); base.OnModelCreating(modelBuilder); } } We are using Model First, and have our own generated code to follow our internal development patterns. So we are not using the out of the box

entity framework plural table names

妖精的绣舞 提交于 2020-01-02 10:09:25
问题 I am trying to get EF 5 to generate singular table names. I have the following code in my DbContext... public partial class LiveoModelContainer : DbContext { protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); base.OnModelCreating(modelBuilder); } } We are using Model First, and have our own generated code to follow our internal development patterns. So we are not using the out of the box

EF Database first how to update model for database changes?

对着背影说爱祢 提交于 2020-01-02 07:17:08
问题 In a class library Ado.net Entity Data Model is has generated POCO classes. These were generated fine for the first time. But database changes are not being reflected. In edmx diagram right clicking and choosing Update Model from Database show newly created table but it do not add table even after selecting it to add. I tried running .tt (by right click and Run custom tool) but even it did not regenerated the Poco classes as per latest DB changes. Help please 回答1: Not a fix but a workaround:

FirstOrDefault call in entity framework is cached but database is changed

血红的双手。 提交于 2020-01-02 06:50:09
问题 I have a strange issue, which I haven't experienced before. I use Entity Framework to retrieve my records. I have the following call: var dbOrganisation = repository.DbOrganisation.FirstOrDefault(c => c.Id == id); I expect no caching of this call. So when I make this call, I expect it to query the database and retrieve the latest DbOrganisation object. But that is not what happens. I call this method relatively two times relatively short time after eachother (~5-10 seconds). But in this

Why does EF 5.0 not support this EF 4.x LINQ syntax when compiling to sql?

时光怂恿深爱的人放手 提交于 2020-01-01 08:35:39
问题 I have some code that was recently upgraded from EF 4.2 to EF 5.0 (actually EF 4.4 since I am running on .Net 4.0). I have discovered that I had to change the syntax of my query, and I'm curious as to why. Let me start off with the problem. I have an EventLog table that is populated by the client periodically. For each event log an entry is created in a Report table. This is the query that is run periodically to discover any event logs that do not have an entry in the Report table yet. The

Keep list of foreign keys in many-to-many Entity Framework relationship

六月ゝ 毕业季﹏ 提交于 2020-01-01 08:22:30
问题 I have a many-to-many relationship in my code-first Entity Framework model. Imagine we have two tables, "Company" and "Article", that have such relationship in between. My simplified code model looks like the following: public class Article { public int Id { get; set; } public string Text { get; set; } public virtual ICollection<Company> Companies { get; set; } } public class Company { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Article> Articles {

EF5 code first with ASP.NET Web API: Update entity with many-to-many relationship

穿精又带淫゛_ 提交于 2020-01-01 05:23:12
问题 I'm trying to update a Customer in my database using ASP.NET Web API and Entity Framework 5 code-first, but it's not working. My entities look like this: public class CustomerModel { public int Id { get; set; } public string Name { get; set; } // More fields public ICollection<CustomerTypeModel> CustomerTypes { get; set; } } public class CustomerTypeModel { public int Id { get; set; } public string Type { get; set; } [JsonIgnore] public ICollection<CustomerModel> Customers { get; set; } }