ef-code-first

One to one relationship, different key column name, Entity Framework, Code First approach

核能气质少年 提交于 2019-12-21 05:11:17
问题 I have two tables that have already been created. Document and DocumentStyle . They have a one to one relationship through the DocumentID column. However, it is called Id in Document table, and DocumentId in DocumentStyle table. Something like this > Document DocumentStyle > |----------| |----------------| > |Id - Key |<------>|DocumentId- key | > |Name-VChar| |Color -VChar| > |Desc-VChar| |Font VChar | > |----------| |----------------| I'm getting the following error in VS The

One to one relationship, different key column name, Entity Framework, Code First approach

自作多情 提交于 2019-12-21 05:11:07
问题 I have two tables that have already been created. Document and DocumentStyle . They have a one to one relationship through the DocumentID column. However, it is called Id in Document table, and DocumentId in DocumentStyle table. Something like this > Document DocumentStyle > |----------| |----------------| > |Id - Key |<------>|DocumentId- key | > |Name-VChar| |Color -VChar| > |Desc-VChar| |Font VChar | > |----------| |----------------| I'm getting the following error in VS The

Keep Database Content On Model Change

主宰稳场 提交于 2019-12-21 05:04:58
问题 Using the code-first approach available in the new 4.1 RC. Is there any way to persist the current data stored in a database when the mode changes? The database is created by the entity framework, and usually the database is dropped and recreated on model changes. Obviously as soon as the model is changed it will not be possible to use the context object to connect to the database to retrieve the data, so what are the options? 回答1: Code first doesn't support database migration / evolution yet

Manually editing database in code first entity framework

谁说胖子不能爱 提交于 2019-12-21 04:00:18
问题 I have been trying out EF 4.1 ( code first ) with MVC 3. I am thinking ahead to when the application will need changes. I tested a couple of scenarios. I like the idea of manually editing the database when the model (my POCOs) would changed. ASP.NET error when I change the model : "The model backing the 'CTCMContext' context has changed since the database was created. Either manually delete/update the database..." Now, it says that I can " manually update the database ", but I did and still

Entity Framework 4 - Mapping non-public properties with CTP5 (code first) in a persistence unaware context

南笙酒味 提交于 2019-12-21 03:46:12
问题 I know the question already has a solution (eg. this question) but I really can't afford to attach the mapping logic in the same assembly where the domain (POCO classes) is. Is there any other way? I found this nice blog post but I couldn't get it working. Here is the model: public class Institute { /** Code omitted **/ protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; } private InstituteTextSet _TextSets; public InstituteTextSet Texts { get { if (_TextSets == null)

Entity Framework 4 - Mapping non-public properties with CTP5 (code first) in a persistence unaware context

烂漫一生 提交于 2019-12-21 03:46:03
问题 I know the question already has a solution (eg. this question) but I really can't afford to attach the mapping logic in the same assembly where the domain (POCO classes) is. Is there any other way? I found this nice blog post but I couldn't get it working. Here is the model: public class Institute { /** Code omitted **/ protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; } private InstituteTextSet _TextSets; public InstituteTextSet Texts { get { if (_TextSets == null)

Select Specific Columns from Database using EF Code First

試著忘記壹切 提交于 2019-12-21 03:42:23
问题 We have a customer very large table with over 500 columns (i know someone does that!) Many of these columns are in fact foreign keys to other tables . We also have the requirement to eager load some of the related tables. Is there any way in Linq to SQL or Dynamic Linq to specify what columns to be retrieved from the database? I am looking for a linq statement that actually HAS this effect on the generated SQL Statement: SELECT Id, Name FROM Book When we run the reguar query generated by EF,

Entity Framework Code First Mapping

旧时模样 提交于 2019-12-21 01:39:11
问题 I have two classes, the Group class has a many to many relationship with the User class (representing the groups a user belongs to) and then the group also has a relationship of one to many with the user class (representing the owner of a group). How can I map this? public class User { public int Id { get; set; } public string Avatar { get; set; } public string Name { get; set; } public string Message { get; set; } public virtual ICollection<Group> OwnedGroups { get; set; } public virtual

Entity Framework Code First Mapping

亡梦爱人 提交于 2019-12-21 01:39:09
问题 I have two classes, the Group class has a many to many relationship with the User class (representing the groups a user belongs to) and then the group also has a relationship of one to many with the user class (representing the owner of a group). How can I map this? public class User { public int Id { get; set; } public string Avatar { get; set; } public string Name { get; set; } public string Message { get; set; } public virtual ICollection<Group> OwnedGroups { get; set; } public virtual

MigrateDatabaseToLatestVersion not executed

删除回忆录丶 提交于 2019-12-20 18:18:59
问题 I can't figure out why my latest migration is not getting executed automatically on application startup (or at least on first access of the database context). I used to run update-database manually in development, but I want to test whether it will upgrade automatically on my hosted test environment. In Application_Start(): Database.SetInitializer<FepazoContext>( new MigrateDatabaseToLatestVersion<FepazoContext, FepazoConfiguration>()) In FepazoConfiguration: internal sealed class