entity-framework

Why does EntityFramework append a 1 by default in edmx after the database entities?

不想你离开。 提交于 2020-01-15 03:11:50
问题 Why does EntityFramework add a 1 by default to a newly created EDMX file?. Say I have a database called EmployeesDB , choosing Add > New ADO.Net Data Entity data model and choosing this database in the wizard creates multiple files, including the EmployeeDB.Designer.cs , where we have public partial class SchoolDBEntities1 : ObjectContext Why is this 1 needed here? It just feels like one of those quick-and-dirty code snippets "Name it like this for now, and give it a proper name latter things

Specify a cascading delete for parent / child relationships?

房东的猫 提交于 2020-01-14 19:23:28
问题 Model: public class MenuItem { public Guid Id {get;set;} public virtual Guid? ParentMenuItemId {get;set;} public virtual MenuItem ParentMenuItem {get;set;} public virtual ICollection<MenuItem> ChildMenuItems {get;set;} } current mapping: HasOptional(m => m.ParentMenuItem).WithMany(p => p.ChildMenuItems).HasForeignKey(m => m.ParentMenuItemId); I tried adding the WillCascadeOnDelete(true) , but I got an error. How should I update my mapping to allow for cascading deletes? So, If I delete a

Database First to Code First EF - Migrations Key and Constraint Names not matching DB

烈酒焚心 提交于 2020-01-14 14:23:57
问题 I recently updated my project from Database First to a Code First Model, using this method: Link Everything seemed to be working until I wanted to update my FK and PKs on an existing table. This was a 1-0, 1-1 relationship. So the PK of Company table was the FK and PK of the DriverScorecardSetting table. So this is the entity that the Tool generated for the DriverScorecardSetting table. [Table("DriverScorecardSetting")] public partial class DriverScorecardSetting { [Key] [DatabaseGenerated

Database First to Code First EF - Migrations Key and Constraint Names not matching DB

柔情痞子 提交于 2020-01-14 14:23:06
问题 I recently updated my project from Database First to a Code First Model, using this method: Link Everything seemed to be working until I wanted to update my FK and PKs on an existing table. This was a 1-0, 1-1 relationship. So the PK of Company table was the FK and PK of the DriverScorecardSetting table. So this is the entity that the Tool generated for the DriverScorecardSetting table. [Table("DriverScorecardSetting")] public partial class DriverScorecardSetting { [Key] [DatabaseGenerated

Linq VAR and Typed Object

血红的双手。 提交于 2020-01-14 14:19:29
问题 I would like a sample of code. At the moment I use linq in c# and asp.net 4 ef4 var querySlotOrder = from slot in context.CmsSlots where slot.SlotId == myCurrentSlotId select slot; if (querySlotOrder.SlotOrder == myNewSlotOrder) e.Cancel = true; This linq query return only a record. Using VAR I cannot get the Typed Object and I cannot access its property SlotOrder. How to change the query? thanks for your help Usefully resource on the topic: http://msdn.microsoft.com/en-us/library/bb384065

Entity Framework not Saving Changes into Database

南楼画角 提交于 2020-01-14 12:20:10
问题 I'm puzzled as to why this code is not working, it should save changes to database after the loops but when I place the SaveChanges method inside the loop, it saves the record into the database but outside it doesn't save anything? it's about only 300 ~ 1000 records static bool lisReady = false; static bool sacclReady = false; static void Main(string[] args) { Logger("Starting services"); ConnectDBLis().Wait(); ConnectDBSaccl().Wait(); Thread.Sleep(1000); if (lisReady & sacclReady){ //start

Entity Framework not Saving Changes into Database

陌路散爱 提交于 2020-01-14 12:17:04
问题 I'm puzzled as to why this code is not working, it should save changes to database after the loops but when I place the SaveChanges method inside the loop, it saves the record into the database but outside it doesn't save anything? it's about only 300 ~ 1000 records static bool lisReady = false; static bool sacclReady = false; static void Main(string[] args) { Logger("Starting services"); ConnectDBLis().Wait(); ConnectDBSaccl().Wait(); Thread.Sleep(1000); if (lisReady & sacclReady){ //start

.Include() .Where() .Select() in Linq to Entities Query

╄→гoц情女王★ 提交于 2020-01-14 11:51:22
问题 I have a Linq query that queries the following tables: Tasks with a one-to-many link to: TaskLinks and TaskLinks has a one-to-one link to a Table called Entities. I am trying to select the task, eager load (via .Include) the TaskLinks and select the Entity linked to the TaskLink. But I need to filter the Task (by Access Level int) and the TaskLinks so that I don't include any Inactive (bool) records. Here is my Linq query: Tasks.Where(t => t.AccessLevel <= 5) .Include(tl => tl.TaskLinks.Where

Polymorphic cross-associations on Entity Framework

半腔热情 提交于 2020-01-14 11:12:58
问题 OK, this is an interesting and most importably real urgent problem for me to solve... In order for others to neatly comprehend it, I've stretched myself to make a well illustrated post. The Object Model So I have this simple, easy and "beautiful" model in mind. See the first picture. (You can ignore PathEntry , it's not relevant in my situation.) The idea is that a MediaFeedItem owns: a collection of ThumbnailFileEntries (accesible through the ThumbnailFiles property) at most 1 raw FileEntry

Polymorphic cross-associations on Entity Framework

依然范特西╮ 提交于 2020-01-14 11:07:38
问题 OK, this is an interesting and most importably real urgent problem for me to solve... In order for others to neatly comprehend it, I've stretched myself to make a well illustrated post. The Object Model So I have this simple, easy and "beautiful" model in mind. See the first picture. (You can ignore PathEntry , it's not relevant in my situation.) The idea is that a MediaFeedItem owns: a collection of ThumbnailFileEntries (accesible through the ThumbnailFiles property) at most 1 raw FileEntry