entity-framework-ctp5

Avoiding Circular referencing providing too much data

淺唱寂寞╮ 提交于 2019-12-12 03:39:17
问题 I followed all the procedures to avoid circular referencing in my Wines/Vineyard project. But I am getting data I do not want: I do not want every listing of wine which has an affiliated vineyard to then have that vineyard list EVERY wine every time the vineyard is listed per wine. How can I stop this? I do not want to do anonymous types. UPDATE: My DbContext: public DataContext() { Configuration.LazyLoadingEnabled = false; Configuration.ProxyCreationEnabled = false; } My Route Config: config

Entity Framework CTP 5 RelatedTo Attribute not working

﹥>﹥吖頭↗ 提交于 2019-12-12 01:48:22
问题 Using Entity Framework CTP 5 I am trying to make a list of foreign keys in my class. But I keep getting an error which says RelatedTo can not be found. Here is the code: public class VertragsVerweis : GenericBLL { [Key] public String Uid { get; set; } public String VertagsVerweisNr { get; set; } public String Bezeichnung { get; set; } public Boolean Reparatur { get; set; } [RelatedTo(RelatedProperty="Artikel")] public List<Artikel> Artikelen { get; set; } } This gives me the error: Error 2

DbContext fails to initialize Model-first database

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:25:08
问题 Update : It turns out I had (hidden away in my POCO objects) a property with an abstract type. Removing this property solves the issue. I'm trying to have a model-first scenario with entity framework 4 ctp 5 generate my database (currently using a SQL Server CE4 backend, but I can reproduce on a Sql Server 2008 backend) from my model. I think I might have messed up my model definition somehow, but I can't seem to figure out how and the error message leaves me none the wiser. My DbContext

Entity Framework Code First - Add Child Entity to Parent by Primary Key

梦想与她 提交于 2019-12-11 07:02:13
问题 In Entity Framework Code First CTP5 is it possible to add a child entity to a parent entity collection using only the primary key of the child? My goal is to avoid having to first load the child entity from the data store. For bonus points, can this be accomplished using only the parent and child primary keys (i.e. without loading any entities at all)? 回答1: Compiled in my head against CTP4 so be aware. public void AddPersonToList(int id, int toAdd) { var mailList = new MailList { ID = id,

EF4 CTP5, mapping different entities to the same (existing) table

痴心易碎 提交于 2019-12-11 05:22:17
问题 By code-first approach (but with an existing db schema), we are trying to map 2 different entities (Customer and Resource) to the same table. Both entities has the same keys and mapping. However, when running the app, we have a runtime error telling us that mysterious message: System.InvalidOperationException: Type 'Resource' cannot be mapped to table 'CLIENT' since type 'Customer' also maps to the same table and their primary key names don't match. Change either of the primary key property

Issue loading child entity of a parent entity. Unidirectional mapping and 1 to 0..1 relationship with a Shared primary Key?

纵饮孤独 提交于 2019-12-11 03:23:22
问题 When I try to load child entity of parent entity it loads with default values. If i try to load explicitly it throws exception Multiplicity constraint violated . The role 'Association_Customer_Target' of the relationship 'CodeFirstNamespace.Association_Customer' has multiplicity 1 or 0..1. This exception is thrown while retrieving the child entities of a complex graph. I have a graph Association which has a child entity Customer with a relationship of one to zero or one and has an Independent

How to map many-to-many relationships in Entity Framework CTP5?

萝らか妹 提交于 2019-12-10 23:13:11
问题 I'm trying to map 2 types (user -> languages) using 3 tables (user - junction table - languages), and looks like the modelBuilder is expecting both types to have a reference to each other (like user.languagesSpoken, and language.UsersSpeaking). So basically I can build something like modelBuilder.Entity<User>().HasMany(x=>x.LanguagesSpoken).WithMany(x=>x.UsersSpeaking) . I don't need a reference from language to user, however - and can't figure out how to map that.. Also, is there a way to

UnitOfWork Implementation

故事扮演 提交于 2019-12-09 13:13:53
问题 Ive been able to implement a little cool unit of work to work with entity framework. I came up with .. public class UnitOfWork : IUnitOfWork { private Database _database; private IDatabaseFactory _databaseFactory; private DbTransaction transaction; public UnitOfWork(IDatabaseFactory databaseFactory) { _databaseFactory = databaseFactory; _database = Database; transaction = _database.Database.Connection.BeginTransaction(); } public Database Database { get { return _database ?? (_database =

EF CTP5 - Context Inheritance Across Multiple Assemblies

巧了我就是萌 提交于 2019-12-08 04:39:20
问题 I have two assemblies, each with models and a model context. The first assembly model context is derived from DbContext. The second assembly model context is derived from the first assembly model context. This works, except the database generation fails because the first assembly models aren't considered when generating the database. Is there a way to ensure that the first assembly models are properly considered during database generation? 回答1: I solved this by loading the other assembly's

entity framework ctp5 get unproxied entity

这一生的挚爱 提交于 2019-12-07 15:39:53
问题 EF CTP 5. I have a single instance where I would like to get the unproxied entity. I can't seem to find a way to do this. I don't want to disable proxy creation all together, just need it for this one query. Can anyone help? Here is a simple example: var myEntity = DbContext.Entities.Find(1); var unproxy = myEntity...? 回答1: I believe the only possibility is to create new instance of DbContext and turn proxy creation off just to execute this query. The reason is that DynamicProxy is type