ef-code-first

Relate Multiple Tables to Single General Purpose Table in Entity Framework Code First

可紊 提交于 2019-12-08 06:11:42
问题 Many times I have a general purpose entity that other entities contain a collection of. I don't want to have a new collection entity for each parent entity type that needs it but would like to re-use a single general purpose entity. For performance reasons, I also don't want to explicitly define many-to-many relationships as in this answer. The simplest example would be a collection of strings. public class MyString { public Guid Id { get; set; } public string Value { get; set; } } public

DDD Modules and EF Code First

耗尽温柔 提交于 2019-12-08 06:04:04
问题 I am trying to follow Domain Driven Design using VS.NET 2012 & EF5. I might have more than 250 Tables (and similar number of POCO Entity classes). If I decide to keep policy/rules/validation, all in one project/.dll, it is gonna be very hefty .dll and multiple developers working on same domain project will make it difficult to work together. To keep Domain Layer Manageable: I divided it into different Modules. Each module have it's own Domain project & Service Layer. All the modules will have

EF Code First on existing database, mapping one to many

旧街凉风 提交于 2019-12-08 05:47:37
问题 I have a database generated by application which I can't modify (I can add tables, views and such but I can't modify existing tables, add columns to them). I work on a web application which uses BreezeJS to allow the client-side part of the web app query for the data via OData protocol. Measurement table has following structure: MeasurementId INT DeviceId INT FOREIGN KEY REFERENCES Devices (DeviceId) Name VARCHAR, PRIMARY KEY (MeasurementId) What I need is to add nullable ParentId self

Multiple foreign keys to the same parent table

蓝咒 提交于 2019-12-08 05:16:12
问题 I have the following simplified classes using EF 5 code-first, where my class B has multiple FK's pointing back to class A. public class A { public int Id {get;set;} ICollection<B> Bs {get;set;} } public class B { public int Id {get;set;} public int A1Id {get;set;} public int A2Id {get;set;} public int A3Id {get;set;} [ForeignKey("A1Id")] public A A1 {get;set;} [ForeignKey("A2Id")] public A A2 {get;set;} [ForeignKey("A3Id")] public A A3 {get;set;} } When I try to build my table I get this

Logging history of user changes in EF CodeFirst

戏子无情 提交于 2019-12-08 04:58:52
问题 I want save history of user changes on DB Records. Changes such as edit records (for example value of FirstName field changed from 'n ' to 'x' by user1 in yyyy/dd/mm") , Delete Records and ... . please suggest a method to implement this in EF codefirst. After Edit: And which one is better? 1.Create one table to save all tables log 2.Create a table for each table in database 回答1: Override the SaveChanges method. In your SaveChanges method loop through the entries using ObjectStateManager

Entity Framework Code First - Create Database with MySql? [closed]

淺唱寂寞╮ 提交于 2019-12-08 04:50:47
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I just wanted to try Entity Framework to use it instead of NHibernate. I'm using a MySql database. So I did few tests with the code first system.

.net mvc razor dropdowns for foreign keys

丶灬走出姿态 提交于 2019-12-08 04:48:35
问题 Ok, this seemed simple, but is making my head spin. I have created models based on CodeFirst. public class Category { public int ID { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } public class SubCategory { public int ID { get; set; } public Category category { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } Now when i auto-generate the controller and view for SubCategory it (out-of-the-box) lets me create new

This SqlTransaction has completed; it is no longer usable. Entity Framework Code First

笑着哭i 提交于 2019-12-08 04:28:19
问题 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.ComponentModel.DataAnnotations; using System.Data.Entity; namespace SqlEFTester { class Program { static void Main(string[] args) { ConnectionManager connectionManager = new ConnectionManager(); SqlConnection conn = connectionManager.Connection; conn.Open(); //BEGIN TRAN SqlTransaction tran = conn.BeginTransaction(); //Will do some legacy work using SqlTransaction,

Move property to new Entity in Entity Framework Code First Migration

岁酱吖の 提交于 2019-12-08 04:12:54
问题 I'm using Entity Framework Code First approach in my project. I have a problem with database migration. Now I have the entity public class Event { public int Id { get; set; } public string Title { get; set; } public string City { get; set; } } I have already have data in my existing DataBase. Now I want to extend City property, like this public class Event { public int Id { get; set; } public string Title { get; set; } public virtual Location Location { get; set; } } so, City become to

ASP.NET MVC : Context type not found in assembly

谁都会走 提交于 2019-12-08 03:57:28
This is my first asp.net mvc project. I used EF code first approach and created a separate class library to write my model and context. I also referenced the class library in mvc project. But now after creating few more new models when I try to enable migration, it gives me an error. I also tried all the possible solutions mentioned here : No context type found in the assembly. ASP.NET MVC4 Still problem remains the same. Am I missing something? This is code for Context Class: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using