entity-framework-4

Entity framework and inheritance: NotSupportedException

被刻印的时光 ゝ 提交于 2020-01-01 08:48:45
问题 I'm getting System.NotSupportedException: All objects in the EntitySet 'Entities.Message' must have unique primary keys. However, an instance of type 'Model.Message' and an instance of type 'Model.Comment' both have the same primary key value but I have no idea what this means. Using EF4, I have a bunch of entities of type Message. Some of these messages are actually a subtype, Comment, inheritance by table-per-type. Just DB.Message.First(); will produce the exception. I have other instances

adding List of objects to Context in ef

雨燕双飞 提交于 2020-01-01 07:28:28
问题 Is it possible to add list of object to Context in entity framework without using foreach addObject ? thanks for help 回答1: Generally you can't do that - you have to do it in a loop. In some cases, however, you can avoid adding every object - specifically, if you have an entity graph and you add the parent node. E.g. if you have a Company object that has a collection of Employees : context.AddToCompanies(company); /* The following loop is not necessary */ /* The employees will be saved

Entity Framework CTP4 and composite keys

和自甴很熟 提交于 2020-01-01 06:38:30
问题 I was playing with EntityFramework CTP4 and decided to apply it to one of my current projects. The application uses a SQLServer database and there is one table with a composite key. Say, table "MyEntity" has "Key1" and "Key2" as both foreign keys (individually) and as a composite primary key. I made a configuration class derived from EntityConfiguration : class MyEntityConfiguration : EntityConfiguration<MyEntity> { public MyEntityConfiguration() { HasKey(m => m.Key1); HasKey(m => m.Key2); }

Disabling Entity Framework's default value generation (Code First)

≡放荡痞女 提交于 2020-01-01 04:45:12
问题 I have a column in the database that cannot be null, and I want to set it to have a default value in the database . The problem is that entity framework seems to create a default value itself (for example, int => 0), and completely ignores the default value constraint in the database. Is there any way to disable this default valuing of entity framework? 回答1: Natively, Entity framework do not allows this. You have to do some code to it. This answer from another site seems to had solved the

References for DBContext, DBSet<> in Entity Framework

穿精又带淫゛_ 提交于 2020-01-01 03:56:06
问题 I am trying to use ADO.Net Codefirst feature of latest Entity Framework 4.0. As part of that I have installed Entity Framework CTP 4 from Microsft and using Scott's tutorial to create the model first. Inside the tutorial DBContext and DBSet<> is specified. Could some tell what is the reference to be used in order to access this class. I have used the following references however nothing happens for DBContext and DBSet<> System.Data.Entity System.Data.Entity.Design 回答1: Use CTP5 instead it is

EF4 How to expose the join table in a many to many relationship

烂漫一生 提交于 2020-01-01 00:46:03
问题 Say I have the following tables: Essence, EssenceSet, and Essence2EssenceSet where Essence2EssenceSet holds just the IDs of the 1st 2 tables to form the M:M relationship. In EF since Essence2EssenceSet has no other fields it is not exposed in the model. I find this makes it difficult to insert records into this table when I already have the 2 IDs needed to create the record but don't necessarily have the Essence and EssenceSet records loaded (Just their IDs) Is there a way to tell EF to not

Advice on POCO Validation with ASP.NET MVC/Entity Framework

大憨熊 提交于 2019-12-31 10:43:02
问题 Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data Context) Repository Pattern Unit of Work Pattern Dependency Injection Service Layer mediating Controller -> Repository So basically, all the cool stuff. :) Flow of events for a basic UI operation ("Adding a Post"): Controller calls Add(Post) method on service layer Service layer calls Add(T) on repository Repository calls AddObject(T) on custom data context Controller calls Commit() on Unit of Work

Advice on POCO Validation with ASP.NET MVC/Entity Framework

拟墨画扇 提交于 2019-12-31 10:42:13
问题 Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data Context) Repository Pattern Unit of Work Pattern Dependency Injection Service Layer mediating Controller -> Repository So basically, all the cool stuff. :) Flow of events for a basic UI operation ("Adding a Post"): Controller calls Add(Post) method on service layer Service layer calls Add(T) on repository Repository calls AddObject(T) on custom data context Controller calls Commit() on Unit of Work

.net MVC Simple Membership Authentication with Database

左心房为你撑大大i 提交于 2019-12-31 08:15:00
问题 Using Code First Entity Framework with .NET MVC 4 I have created a new Web Application and populated the database with object as shown below. public class GratifyGamingContext : DbContext { public DbSet<Game> Games { get; set; } public DbSet<Genre> Genres { get; set; } public DbSet<UserProfile> UserRepository { get; set; } } I want to use my UserRepository table instead of the inbuilt UserContext class from AccountModel.cs for my user account access since I can't get that the work with my

.net MVC Simple Membership Authentication with Database

我只是一个虾纸丫 提交于 2019-12-31 08:14:32
问题 Using Code First Entity Framework with .NET MVC 4 I have created a new Web Application and populated the database with object as shown below. public class GratifyGamingContext : DbContext { public DbSet<Game> Games { get; set; } public DbSet<Genre> Genres { get; set; } public DbSet<UserProfile> UserRepository { get; set; } } I want to use my UserRepository table instead of the inbuilt UserContext class from AccountModel.cs for my user account access since I can't get that the work with my