entity-framework

Entity Framework Many to Many and Eager Loading

丶灬走出姿态 提交于 2020-01-24 08:48:27
问题 I'm using Entity Framework 4.1 with MySql and having a problem with the eager loading of a many to many relationship. A simplified version of the affected tables looks like: CabinCategory - CabinCategoryId CabinGrade - CabinGradeId, CabinCategoryId Deck - DeckId DeckCabinGrades - DeckId, CabinGradeId <--- Join table I'm ultimately trying to access CabinCategory.CabinGrade.Deck I think I've managed to map this successfully using modelBuilder.Entity<CabinGrade>() .HasMany(c => c.Decks)

Entity Framework Many to Many and Eager Loading

只谈情不闲聊 提交于 2020-01-24 08:48:09
问题 I'm using Entity Framework 4.1 with MySql and having a problem with the eager loading of a many to many relationship. A simplified version of the affected tables looks like: CabinCategory - CabinCategoryId CabinGrade - CabinGradeId, CabinCategoryId Deck - DeckId DeckCabinGrades - DeckId, CabinGradeId <--- Join table I'm ultimately trying to access CabinCategory.CabinGrade.Deck I think I've managed to map this successfully using modelBuilder.Entity<CabinGrade>() .HasMany(c => c.Decks)

Incorrect value when saving enum

流过昼夜 提交于 2020-01-24 05:05:26
问题 I'm having a little difficulty getting Entity Framework 5 Enums to map to an integer column in a migration. Here's what the code looks like: [Table("UserProfile")] public class UserProfile { public enum StudentStatusType { Student = 1, Graduate = 2 } [Key] public int UserId { get; set; } public string UserName { get; set; } public string FullName { get; set; } public StudentStatusType Status { get; set; } } The migration looks like this: public partial class EnumTest : DbMigration { public

Does the Entity Framework DbEntityEntry.Property method use reflection?

自作多情 提交于 2020-01-24 04:31:05
问题 This question is about this code: entityEntry.Property("WhateverProperty").CurrentValue = 1; I answered this question yesterday and if you notice in the comments to the question (not the answer), one of the members @gertarnold said this: entityEntry.Property("InsertedBy") doesn't use reflection, it reads the EF metadata. Sure it uses the EF metadata to figure out if the entity has that property but I am pretty sure somewhere down the line they would have to use reflection to set the property

Entity Framework - Eager load two many-to-many relationships

不羁的心 提交于 2020-01-24 04:20:05
问题 Sorry for this being so long, but at least I think I got all info to be able to understand and maybe help? I would like to load data from my database using eager loading. The data is set up in five tables, setting up two Levels of m:n relations. So there are three tables containing data (ordered in a way of hierarchy top to bottom): CREATE TABLE [dbo].[relations]( [relation_id] [bigint] NOT NULL ) CREATE TABLE [dbo].[ways]( [way_id] [bigint] NOT NULL ) CREATE TABLE [dbo].[nodes]( [node_id]

Updating Nested Objects in Entity Framework

余生颓废 提交于 2020-01-24 04:12:48
问题 recently I discover that EF doesn't update nested object. For few days I try to figure out how to do this but unfortunately I'm stuck with this problem. I have Object public class ProjectEntity : AuditableEntity<int> { public string CustumerCompany { get; set; } public string CustomerRepresentative { get; set; } public string ProjectTitle { get; set; } public string WwsNumber { get; set; } [ForeignKey("ParentProjectId")] public virtual ProjectEntity ParentProject { get; set; } public int?

Storing graph with EF Code First

痴心易碎 提交于 2020-01-23 23:34:49
问题 I'm trying to save a graph into a database as described here with EF Code First. I defined property with collection of adjacent nodes: public class Node { public int NodeId { get; set; } public string NodeName { get; set; } public ICollection<Node> Nodes { get; set; } } but EF generated only one table for this model: dbo.Nodes NodeId (PK, int, not null) NodeName (nvarchar(max), null) Node_NodeId (FK, int, null) How to force EF to generate many-to-many relationship? Are there any other ways to

Storing graph with EF Code First

…衆ロ難τιáo~ 提交于 2020-01-23 23:33:26
问题 I'm trying to save a graph into a database as described here with EF Code First. I defined property with collection of adjacent nodes: public class Node { public int NodeId { get; set; } public string NodeName { get; set; } public ICollection<Node> Nodes { get; set; } } but EF generated only one table for this model: dbo.Nodes NodeId (PK, int, not null) NodeName (nvarchar(max), null) Node_NodeId (FK, int, null) How to force EF to generate many-to-many relationship? Are there any other ways to

Entity Framework: Can DB Contexts Have Foreign Keys Across Different Schemas? [closed]

跟風遠走 提交于 2020-01-23 22:48:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . We have a single database with multiple schemas. Company architect wants to have Entity Framework DbContext for each schema. Additionally, foreign key relationships exist between different schemas. In scaffolding a schema today, received this error: Error: For foreign key FK

Entity Framework: Can DB Contexts Have Foreign Keys Across Different Schemas? [closed]

风格不统一 提交于 2020-01-23 22:46:00
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . We have a single database with multiple schemas. Company architect wants to have Entity Framework DbContext for each schema. Additionally, foreign key relationships exist between different schemas. In scaffolding a schema today, received this error: Error: For foreign key FK