code-first

Entity Framework database mapping relationships (Duplicate creation using Seed() method)

你。 提交于 2019-11-29 16:21:16
I created a post with an issue and another issue . These can be looked at for references but i consider them as handled. My question arising from these issues and the action i (need or not need) to apply bothers me because i don't quite understand EF its behavior and expectations. I have a Product, PurchasePrice and SalesPrice entity where my initial thought was that 1 Product can have multiple PurchasePrices but that 1 PurchasePrice only can exist in 1 Product (same for SalesPrice). Therefore these relations: // NOTE that BaseEntity just has a "int ID" prop and datetimes/stamps public class

Entity Framework - CTP4 - Code First - How to turn off the automatic pluralization?

删除回忆录丶 提交于 2019-11-29 14:54:43
问题 My entity name is "Contact" and my table name is "Contact". However, the default pluralization support is making EF4 to look for a table named "Contacts". Anybody has any idea on how to turn off the pluralization support? This post has got some details on pluralization support. But still does not give me an answer. I see the following text in this post. First of all, I dont know which physical .tt file I need to make this change. Also, I want to have this feature turned off only for one app

Code-First Reference one-to-many

核能气质少年 提交于 2019-11-29 14:50:25
问题 I have the following two tables: LOCALIZATION Id int Text string DINER Id int Name string Description string Name_LocalizationID int Description_LocationID int Now I want my POCO like this: public class Diner{ public int Id{get;set;} public ICollection<Localization> NameLocalization{get;set;} public ICollection<Localization> DescriptionLocalization{get;set;} } public class Localization{ public int Id{get;set;} public string Text{get;set;} } Question is: How we can map NameLocalization and

Entity Framework Code First 5 Cascade Delete on many to many tables error

心已入冬 提交于 2019-11-29 14:19:36
问题 I've this model public class State { public State() { this.Promotions = new List<Promotion>(); this.Branches = new List<Branch>(); this.Stores = new List<Store>(); } public int Id { get; set; } public string Description { get; set; } public virtual ICollection<Promotion> Promotions { get; set; } public virtual ICollection<Store> Stores { get; set; } public virtual ICollection<Branch> Branches { get; set; } } public class Store { public Store() { this.Promotions = new List<Promotion>(); this

SQLite with EF Code First

会有一股神秘感。 提交于 2019-11-29 14:02:30
问题 After my success using SQLite with NHibernate, I am very happy to use it for testing with Entity Framework Code First. If you have some example connections string and set up demos, that would be great and save a bit of time from my hectic day. Thanks a lot. EDIT: Worth mentioning that I am getting this error during debugging when applying crud actions via the EF "data context": Unable to determine the provider name for connection of type 'System.Data.SQLite.SQLiteConnection'. <system.data>

Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths?

两盒软妹~` 提交于 2019-11-29 12:42:34
I am getting this error when generate Database from Entity Framework Code First. I didn´t see any problem with script: alter table [dbo].[Votes] add constraint [Post_Votes] foreign key ([Post_Id]) references [dbo].[Posts]([Id]) on delete cascade; alter table [dbo].[Votes] add constraint [User_Votes] foreign key ([Voter_Id]) references [dbo].[Users]([Id]) on delete cascade; Each reference is to different tables! I can have just one on delete cascade per table? Edit: I think I found the problem, the bug is EF: If I have 3 tables: Users, Posts and Votes. And the relations: Post.AuthorId -> User

Entity Framework, Code First and One-to-Many relationship across multiple contexts

最后都变了- 提交于 2019-11-29 11:41:07
I am using VS 2010 and Entity Framework code first (version 6). I have two entities each in its own context and I want to create a one-to-many relationship between them. Context 1 has the following entity: public class MyTrust { public int MyTrustID { get; set; } public string MyTrustName { get; set; } } and Context 2 has the following entity: public class MyLocation { public int MyLocationID { get; set; } public int MyTrustID { get; set; } public virtual MyTrust MyTrust { get; set; } } with the following Fluent API modelBuilder.Entity<MyLocation>() .HasRequired(m => m.MyTrust); The migration

How to stop EF4.1 Code-First to create Culstered index for the entity PK

痴心易碎 提交于 2019-11-29 11:33:01
With the following simple entity class, EF4.1 Code-First will create Clustered Index for the PK UserId column when intializing the database. public class User { [Key] public int UserId { get; set; } public int AppId { get; set; } public string UserName { get; set; } } For performance sake, my design goals is to keep the generated Users table physical Clustered according to the AppId coulmn not to the PK. On my Initializer class I've tried to manually drop the autogenerated PK clustered index and create whatever clustered index I need, but no clue here to predict the autogenerated name PK_

Change Fluent API mapping dynamically

淺唱寂寞╮ 提交于 2019-11-29 11:31:02
Our project uses Entity Framework Code First. We wish to have an instance where a very simple POCO represents many tables in the database. It is part of a horizontal partitioning strategy in SQL Azure. SQL Azure does not support file groups, thus it does not support typical partitioning. There are going to be a very large numbers of tables, so using a UNION ALL view as a partitioned view via CHECK CONSTRAINTs on the base tables will not be feasible. Thus, we would prefer to peform the mapping as needed at runtime. However, this occurs in the OnModelCreating event of the DbContext class via

MVC Model Range Validator?

痴心易碎 提交于 2019-11-29 11:28:46
i wnat to validate the datetime, My Code is: [Range(typeof(DateTime), DateTime.Now.AddYears(-65).ToShortDateString(), DateTime.Now.AddYears(-18).ToShortDateString(), ErrorMessage = "Value for {0} must be between {1} and {2}")] public DateTime Birthday { get; set; } but i get the error: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type please help me? mfanto This means the values for the Range attribute can't be determined at some later time, it has to be determined at compile time. DateTime.Now isn't a constant,