ef-code-first

Entity Framework 5 - code first array navigation property one to many with Interface Type

寵の児 提交于 2020-05-13 08:03:11
问题 These are my classes: public class Post : IPost { public int Id { get; set; } public virtual int[] DuplicateOf { get; set; } public virtual ICommentInfo[] Comments { get; set; } } public class CommentInfo : ICommentInfo { public virtual string Author { get; set; } public virtual int Id { get; set; } public virtual string Text { get; set; } public virtual int PostId{ get; set; } [ForeignKey("PostId")] public virtual Post Post { get; set; } } With this CommentConfiguration added to

“Object reference not set to an instance of an object” when creating a new Web API controller with EF Scaffolding in Visual Studio 2012

旧时模样 提交于 2020-05-09 05:07:09
问题 I have an MVC4/Web API project, with an Entity Framework, Code First data model. When I try to create a new API Controller with read/write methods using a data context & model, I get an alert saying "Object reference not set to an instance of an object". I've done a bit of searching and found that some causes are incorrect project type Guids in the .csproj file, incomplete installation of the MvcScaffolding nuget package and one suggestion of installing Powershell 3. I have made sure all my

Adding a second one-to-one relationship with the same table in entity framework

亡梦爱人 提交于 2020-04-17 10:03:31
问题 I am doing code-first entity framework design. I have a table, Account, which has a property, Supervisor: public class Account { public int Id { get; set; } public Account Supervisor { get; set; } } This works beautifully. However, I wish to add an alternate supervisor to the class: public class Account { public int Id { get; set; } public Account Supervisor { get; set; } public Account AlternateSupervisor { get; set; } } When I run Add-Migration AddAlternateSupervisor, the generated code

EF code first, Entities with multiple relations

蹲街弑〆低调 提交于 2020-03-06 04:16:34
问题 Here you can see my reduced entity structure which I would like to store in my Sqlite database. I've a Graph which holds a Set of GraphElements . My Graph consists of Edges , Nodes and Loads which are all different Elements. For a deep-first-search for example each node needs to know its neighbor nodes. Therefore I need the NeigborNodes -List. For other functionalities I need also to know the ConnectedElements -List. class Graph { public int Id { get; set; } public string Name { get; set; }

EF code first, Entities with multiple relations

守給你的承諾、 提交于 2020-03-06 04:14:16
问题 Here you can see my reduced entity structure which I would like to store in my Sqlite database. I've a Graph which holds a Set of GraphElements . My Graph consists of Edges , Nodes and Loads which are all different Elements. For a deep-first-search for example each node needs to know its neighbor nodes. Therefore I need the NeigborNodes -List. For other functionalities I need also to know the ConnectedElements -List. class Graph { public int Id { get; set; } public string Name { get; set; }

ASP.NET MVC/EF Code First error: Unable to retrieve metadata for model

橙三吉。 提交于 2020-02-29 04:28:31
问题 I'm trying to create a controller in MVC4 and I'm getting an error I don't understand (I'm new to MVC). It says "Unable to retrieve metadata for 'CIT.ViewModels.DashboardViewModel'..." and then gives 2 possible problems. One is that the DashboardViewModel has no key defined. The other is that EntitySet 'DashboardViewModels' has no key defined. I defined a key for DashboardViewModel, but that didn't solve the problem. Here is my DashboardViewModel; public class DashboardViewModel { public

ASP.NET MVC/EF Code First error: Unable to retrieve metadata for model

ぐ巨炮叔叔 提交于 2020-02-29 04:28:27
问题 I'm trying to create a controller in MVC4 and I'm getting an error I don't understand (I'm new to MVC). It says "Unable to retrieve metadata for 'CIT.ViewModels.DashboardViewModel'..." and then gives 2 possible problems. One is that the DashboardViewModel has no key defined. The other is that EntitySet 'DashboardViewModels' has no key defined. I defined a key for DashboardViewModel, but that didn't solve the problem. Here is my DashboardViewModel; public class DashboardViewModel { public

Code First: Avoid discriminator column and keep inheritance

雨燕双飞 提交于 2020-02-11 18:53:54
问题 In my project I have: public class BaseEntity { [Key] public int Id {get; set; } } Then I have to define 10+ POCO classes to define the tables in my database: public class MyTable : BaseEntity { //define properties here } Of course, because MyTable inherits from BaseEntity I get that Discriminator field. I want to get rid of the Discriminator field as I do not need the table BaseEntity to be created nor I need to implement some sort of inheritance into my database. Is it possible? 回答1: A

Code First: Avoid discriminator column and keep inheritance

天大地大妈咪最大 提交于 2020-02-11 18:53:49
问题 In my project I have: public class BaseEntity { [Key] public int Id {get; set; } } Then I have to define 10+ POCO classes to define the tables in my database: public class MyTable : BaseEntity { //define properties here } Of course, because MyTable inherits from BaseEntity I get that Discriminator field. I want to get rid of the Discriminator field as I do not need the table BaseEntity to be created nor I need to implement some sort of inheritance into my database. Is it possible? 回答1: A

EF Reverse Engineer Code First does not populate one-to-many & many-to-many properties

主宰稳场 提交于 2020-02-08 09:38:48
问题 I'm not sure if I'm doing things wrong or EF has a bug. I followed this StackOverflow post but to my avail, it still failed to populate. The structure is basically the same. I'm absolutely sure on the data since the keys match up to the data. Eventually, I ended up just manipulating the models in my Service layer just to populate the properties. public TeamsService(IRepositoryAsync<Team> repo, IRepositoryAsync<AspNetUser> userRepo) : base(repo) { _repo = repo; _userRepo = userRepo; } public