code-first

What the purpose of OnModelCreating in EF4 Code-First?

限于喜欢 提交于 2019-12-03 06:53:19
问题 I was curious about what the purpose of OnModelCreating in EF4 Code-First context class? How does it work? 回答1: Here is a nice article in ADO.NET Team Blog. In short, this event is mainly for Fluent mapping. 回答2: OnModelCreating gives you access to a ModelBuilder instance that you can use to configure/customize the model. As the previous answer mentions, you will typically use the code-first fluent API within it. Gil Fink has posted what IMHO is a clearer explanation than the article cited in

Best Practices for Lookup Tables in EF Code-First

旧城冷巷雨未停 提交于 2019-12-03 06:05:01
问题 I'm doing my first project with EF and I'm planning to go the code-first model. I'm trying to find a bit of guidance about handling a fairly classic "lookup table" scenario. I'm dealing with a pretty canonical situation where I'll be persisting address data. So, I have a simple address DTO... public class Address { public int Id { get; set; } public virtual string StreetAddress1 { get; set; } public virtual string StreetAddress2 { get; set; } public virtual string City { get; set; } public

Entity Framework Code First One to One Relationship

眉间皱痕 提交于 2019-12-03 04:36:47
问题 I have the following two models public class Account { public int Id { get; set; } public string Name { get; set; } public int CurrentPeriodId { get; set; } [ForeignKey("CurrentPeriodId")] public virtual Period CurrentPeriod { get; set; } public virtual ICollection<Period> Periods { get; set; } } public class Period { public int Id { get; set; } public int AccountId { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public virtual Account Account { get

EF 4.1 Code First - Determine What Properties Have Changed

牧云@^-^@ 提交于 2019-12-03 03:53:04
问题 I'm using Entity Framework 4.1 Code First. Is there a built-in way to get a list of what properties have changed since the entity was loaded from the database? I know code first detects that an object was changed, but is there a way to get exactly what properties have changed? 回答1: For scalar and complex properties you can use the following to extract the changed property names of an entity myEntity : var entry = context.Entry(myEntity); var namesOfChangedProperties = entry.CurrentValues

DDD with EF Code First - how to put them together?

☆樱花仙子☆ 提交于 2019-12-03 03:51:25
问题 I am learning DDD development for few days, and i start to like it. I (think i) understand the principle of DDD, where your main focus is on business objects, where you have aggregates, aggregates roots, repositories just for aggregates roots and so on. I am trying to create a simple project where i combine DDD development with Code First approach. My questions are: (I am using asp.net MVC) DDD Business Objects will be different than Code First objects? Even if they will probably be the same,

Entity Framework CTP5 Code First, WPF - MVVM modeling

时光怂恿深爱的人放手 提交于 2019-12-03 03:38:33
I have my model all setup for my WPF application and working with entity framework ctp5 code first, here's a sample model class: public class Task { public int ID { get; set; } public int Index { get; set; } public string Content { get; set; } public int Indentation { get; set; } public DateTime Start { get; set; } public decimal Effort { get; set; } public decimal CompletedEffort { get; set; } public decimal Cost { get; set; } } What would be the recommended way to build my view model? My view models will implement INotifyPropertyChanged, I do not want the model classes to have any UI

Entity Framework Code first development Resources and Documentation

安稳与你 提交于 2019-12-03 02:43:56
I know EF4 is still in development but as a newcomer to the subject, I need a document, tutorial etc. with EF 4 code first approach. All the info is in EF 4 Team Blog but scattered around different posts. A full coverage would be really nice. Any one knows of a such place? The best online resource that I've seen so far is Scott Guthrie series of blogs on the new EF “code first” development option: Code-First Development with Entity Framework 4 Entity Framework 4 “Code-First”: Custom Database Schema Mapping Using EF “Code First” with an Existing Database If you are new to the subject, like you

Deploy Entity Framework Code First

梦想与她 提交于 2019-12-03 02:06:24
I guess I should have thought of this before I started my project but I have successfully built and tested a mini application using the code-first approach and I am ready to deploy it to a production web server. I have moved the folder to my staging server and everything works well. I am just curious if there is a suggested deployment strategy? If I make a change to the application I don't want to lose all the data if the application is restarted. Should I just generate the DB scripts from the code-first project and then move it to my server that way? Any tips and guide links would be useful.

How to use MySql and Entity Framework 4.1 code first

本秂侑毒 提交于 2019-12-03 00:37:51
I am trying to use MySQL database in MVCMusicStore http://mvcmusicstore.codeplex.com/ instead of MSSQL. I would like to learn Code first development with MySQL. I had added these code to web.config <connectionStrings> <add name="MusicStoreEntities" connectionString="Server=localhost; Database=MvcMusicStore; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient"/> </connectionStrings> <system.data> <DbProviderFactories> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql

How to specify two navigation properties from entity X to the same target entity, Y?

落爺英雄遲暮 提交于 2019-12-02 18:11:51
问题 Consider that I have an Instructor class: public class Instructor { public InstructorTypesEnum Type { get; set; } public virtual ICollection<Course> Courses { get; set; } public virtual ICollection<Course> CoInstructingCourses { get; set; } } Here, InstructorTypesEnum has two values: instructor and co-instructor. So the two navigation properties Courses and CoInstructingCourses are supposed to return those different courses. Of course I am also having difficulties specifying the coresponding