code-first

Tool to convert Entity Framework EDMX to Code First

一笑奈何 提交于 2019-11-28 07:14:08
Is there a tool to convert an edmx into code-first? I know there was talk of one appearing in a CTP a while back, but I can't find any updates relating to this. There's a guy on the MSDN forums who has written his own (not available yet), but nothing from the EF team. There is no such tool because EDMX offers much more features which cannot be translated into code-first. The only tool available are EF Power Tools CTP1 which allow creating code-first mapping from existing database but it will only create 1:1 image of your database = naming based on database, no inheritance, no splitting, etc.

Where is EntityConfiguration in EF4 VS 2010 RTM?

喜夏-厌秋 提交于 2019-11-28 06:59:15
I cannot find EntityConfiguration. The same question for RC was here but I thought that it would make it to the RTM version. Is it there? nubm EntityConfiguration<> is EntityTypeConfiguration<> UPDATE 7 EF 4.1 Released UPDATE 6 Microsoft ADO.NET Entity Framework 4.1 Release Candidate (EF 4.1 RC) with go-live license is out. EntityConfiguration<> is from CTP5 EntityTypeConfiguration<> UPDATE 5 Our plan is to deliver a Go-Live Release Candidate version of the DbContext API and Code First in mid to late March. This Release Candidate will be titled ADO.NET Entity Framework 4.1 . Approximately a

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

不羁的心 提交于 2019-11-28 06:26:35
问题 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

Change Fluent API mapping dynamically

巧了我就是萌 提交于 2019-11-28 05:02:28
问题 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

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

◇◆丶佛笑我妖孽 提交于 2019-11-28 04:49:12
问题 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

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

♀尐吖头ヾ 提交于 2019-11-28 04:45:35
问题 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

Entity Framework CTP5 Code-First Mapping - Foreign Key in same table

∥☆過路亽.° 提交于 2019-11-28 04:43:22
问题 How would I map something like this using the modelBuilder? Where theres a nullable foreign key referencing the same tables primary key Table: Task taskID int pk taskName varchar parentTaskID int (nullable) FK Task class: public class Task { public int taskID {get;set;} public string taskName {get;set;} public int parentTaskID {get;set;} public Task parentTask {get;set;} } ... modelBuilder.Entity<Task>() .HasOptional(o => o.ParentTask).... 回答1: The following code gives you the desired schema.

MVC Model Range Validator?

大城市里の小女人 提交于 2019-11-28 04:33:11
问题 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? 回答1: This means the values for the Range attribute can't be

in entity framework code first, how to use KeyAttribute on multiple columns

人走茶凉 提交于 2019-11-28 04:26:45
I'm creating a POCO model to use with entity framework code first CTP5. I'm using the decoration to make a property map to a PK column. But how can I define a PK on more then one column, and specifically, how can I control order of the columns in the index? Is it a result of the order of properties in the class? Thanks! You can specify the column order in the attributes, for instance: public class MyEntity { [Key, Column(Order=0)] public int MyFirstKeyProperty { get; set; } [Key, Column(Order=1)] public int MySecondKeyProperty { get; set; } [Key, Column(Order=2)] public string

Lazy vs eager loading performance on Entity Framework

只愿长相守 提交于 2019-11-28 03:29:54
问题 So I have the following model classes on my DbContext: Everytime I render a list of LoanApplication objects I do something like this: var context = new MyContext(); var applications = context.LoanApplications.Where(d => d.PropertyThatIWantToFilter = localVariable); This returns an IQueryable that then I convert to a ViewModel like this on my controller method call: var vm = applications.Select(d => new LoanApplicationViewModel(d)); Inside the LoanApplicationViewModel constructor I accept the