entity-framework-5

Tinyint(byte),SmallInt(Int16) not compatible with Enum in EF5

久未见 提交于 2019-12-20 11:13:31
问题 Using Database first design and having tinyint (or smallint) column: [MyEnumColumn] [tinyint] NOT NULL I mapped this column to Enum Type in EDM with External Type: NSpace.MyEnumType Name:MyEnumType UnderlyingType:Byte Where NSpace.MyEnumType is defined like this: public enum MyEnumType { One, Two, Three, All } Only to get this error when trying to load entity from context: Schema specified is not valid. Errors: No corresponding object layer type could be found for the conceptual type

Entity Framework 5 Code First - How to “start over”?

青春壹個敷衍的年華 提交于 2019-12-20 10:48:29
问题 I've been using EF 5 Code First, successfully, in my app. I have roughly 40 tables. However, I've run into an issue that I can seem to get Migrations to handle correctly. So, what I would like to do is to somehow tell EF to treat the current schema of the database as a new starting point, and start managing it from this point. This way, I can make the necessary schema change manually, and then tell EF to essentially start over from this point. Is there a way I can do this? I presume I'm going

EF 5, update object gives “A referential integrity constraint violation occurred”

荒凉一梦 提交于 2019-12-20 10:01:01
问题 In my model I've got a bunch of domain objects. Now I'm having a problem when trying to update a User-object. The User has a foreignkey relation to the Role object. When I update the User-object without changeing the foreignkey value (FkRoleId) it all works fine. But when I change the role for the current user I want to update I get the error: A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal

How to initialize database with Entity Framework and Membership tables

久未见 提交于 2019-12-20 08:39:50
问题 I have a MVC4 web application that use Entity Framework 5.0 Code First. In Global.asax.cs I have a bootstrapper that initialize the Entity.Database, force the database to be initialized and initialize the database for the Membership. The code is this one: System.Data.Entity.Database.SetInitializer(new DatabaseContextInitializer()); Database.Initialize(true); WebSecurity.InitializeDatabaseConnection(DEFAULTCONNECTION, "UserProfile", "UserId", "UserName", autoCreateTables: true); The

Why are there missing client-side results when using OData options with Entity Framework DBContext?

六眼飞鱼酱① 提交于 2019-12-20 06:20:05
问题 OData and Entity Framework are suppose to work well together, in that OData options will be passed to the EF db context to filter queries - ie. return only the number of records requested from the server as not to inflate the payload rather than all the records then filter. Given the following URL path: /api/Users?$top=10&$skip=10 Given the following controller action: [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)] public IEnumerable<USER> Get(ODataQueryOptions<USER> options) {

Filling child entity with Entity Framework SqlQuery

旧城冷巷雨未停 提交于 2019-12-20 04:19:49
问题 I have two entities in 1:n relationship: Category and Product. public class Category { public int CategoryID { get; set; } public string CategoryName { get; set; } public virtual ICollection<Product> Products { get; set; } } public class Product { public int ProductID { get; set; } public string ProductName { get; set; } public virtual Product { get; set; } } public class context : DbContext { public DbSet<Category> Categories { get; set; } public DbSet<Product> Products { get; set; } } Its

How do I express a “has many through” relationship in Entity Framework 5?

可紊 提交于 2019-12-20 02:53:07
问题 I am attempting to use Entity Framework 5 to query an existing MySQL database. I used code-first to create a code-based model that maps to an existing database following this tutorial on MSDN. I have two tables: users and buddies . A User has an id , a name and an email . A Buddy has a user_id and a buddy_id . A User has many Buddies (which are also Users ). The buddy_id column is a foreign key back into the Users table. So each User has many Users through Buddies . public class User { public

How DbContext initializes automatic DbSet<T> properties?

若如初见. 提交于 2019-12-20 01:43:41
问题 Consider the following class: class MyContext : DbContext { public DbSet<Order> Orders { get; set; } } and instantiating a new object: var mycontext = new MyContext(); Why mycontext.Orders is not null? When it was initialized? Who has initialized it? I'm really confused because the base class (DbConetxt) cannot access the derived class properties so it is not possible that the automatic property was initialized in the base object. 回答1: From looking at the reflected code, when the DbContext

The key component 'Id' is not a declared property on type 'TypeName', when using base class and private setter

允我心安 提交于 2019-12-19 21:46:50
问题 I want to use an abstract base class for entities, which is not mapped on any table: public abstract class Entity { public virtual int Id { get; private set; } } Since Id will be auto-increment, I don't want to allow to change this property from outside. Hence, its setter is private . Here's a sample entity type: public class Order : Entity { public virtual string Customer { get; set; } } ...configuration types: public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity>

ASP .Net Entity Framework .tt Files Not Nesting Under .edmx

烂漫一生 提交于 2019-12-19 19:59:09
问题 I'm running an ASP .NET (v4.5) Web Site Project under VS 2012 Update 2. When I create a new entity model (.edmx) under the App_Code folder, nested under the .edmx file is only the .Designer.cs and the .edmx.diagram files. The associated .tt files are not nested. I think this is why, when I save the model, the T4 templates are not automatically transformed, even though that option is specified in the model properties. Any ideas how to get this working? I cannot use the DependentUpon XML tag in