code-first

Entity Framework CTP5 Code First, WPF - MVVM modeling

大憨熊 提交于 2019-12-03 13:36:57
问题 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

Disabling Entity Framework's default value generation (Code First)

天涯浪子 提交于 2019-12-03 13:16:16
I have a column in the database that cannot be null, and I want to set it to have a default value in the database . The problem is that entity framework seems to create a default value itself (for example, int => 0), and completely ignores the default value constraint in the database. Is there any way to disable this default valuing of entity framework? Simon Dugré Natively, Entity framework do not allows this. You have to do some code to it. This answer from another site seems to had solved the problem for many people. He "hacks" it (as he told) by doing something like that: public partial

What causes “Incorrect syntax near <stored procedure name>” in EF Code First and SQL 2005?

。_饼干妹妹 提交于 2019-12-03 12:48:16
The examples for System.Data.Entity.Database.SqlQuery method I've found appear to work well with SQL 2008 R2 but do not appear to work with SQL 2005. This call will work with SQL 2008 R2: var myEntities = dbContext.Database.SqlQuery<MyEntity>("GetDataFromMySp @EntityId = {0}", entityId); However, in SQL 2005 this statement will throw a SqlException with an error message of "Incorrect syntax near 'GetDataFromMySp'". Solution found by @Dan himself (couldn't post due to rep) The solution I found to this issue was simply to add the keyword "EXEC" to the query: var myEntities = dbContext.Database

Inheritance EF Code-First

梦想与她 提交于 2019-12-03 12:37:10
I have a base object that I dont want to be mapped in DB as an entity, I only want the properties to be added to the object that is mapped in the DB : Not mapped object (dont know if it matters but baseobject is in another assembly): public class BaseObject { public virtual string Prop1 { get; set; } public virtual string Prop2 { get; set; } } Mapped object: public class ChildObject : BaseObject { public virtual string Prop3 { get; set; } public virtual string Prop4 { get; set; } public virtual string Prop5 { get; set; } } What is registered in DbContext public DbSet<ChildObject> ChildObjects

Entity Framework Code first development Resources and Documentation

左心房为你撑大大i 提交于 2019-12-03 12:18:47
问题 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? 回答1: 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

Entity Framework Code First: One-to-Many and Many-to-Many relationships to same table

喜你入骨 提交于 2019-12-03 12:12:26
I have a User model and a Event model in my project. The Event has a creator(User) and has participant(Users) so Event has a one-to-many relationship with User and also a many-to-many relationship to the same table. I had first the one-to-many relationship like this: Public class Event { ... public int CreatedById { get; set; } public virtual User CreatedBy { get; set; } ... } Then when I added the many-to-many relationship the migration doesn't generate the many to many relationship: Public class User { ... public virtual ICollection<Event> Events { get; set; } ... } Public class Event { ...

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

£可爱£侵袭症+ 提交于 2019-12-03 11:19:39
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) _TextSets = new InstituteTextSet(InnerInstituteTexts); return _TextSets; } } } Mapping code: var

How to use MySql and Entity Framework 4.1 code first

佐手、 提交于 2019-12-03 11:04:20
问题 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"

CRUD Views For Many-Many Relationship, Checkboxes

跟風遠走 提交于 2019-12-03 08:37:29
I am having a hard time trying to figure out what I need to do to get this to work. I'm learning ASP.NET MVC CodeFirst with EF. If I make a model I can simply add a controller for that model and add scaffolding to create views that automatically take care of CRUD. But now I have two models, Project and Category. They have a many to many relationship and database is designed correctly with the associative table without having to make a separate model for it. The code for the models is this.... public class Project { public int ProjectId { get; set; } public string Title { get; set; } public

EF 4.1 Mapping Problem

谁说我不能喝 提交于 2019-12-03 07:16:19
I have a class that have a relationship with itself: public class Person { public long ID { get; set; } public string Name { get; set; } public virtual Person Mother { get; set; } public virtual Person Father { get; set; } } When EF 4.1 is trying to map this class I'm getting the follow error: 'Unable to determine the principal end of an association between the types 'Model.Person' and 'Model.person'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.' I already tried the solution of the topic EF 4.1 - Model