entity-framework-4.3

EF4: Why does proxy creation have to be enabled when lazy loading is enabled?

余生颓废 提交于 2019-12-08 05:38:07
问题 I have a project structured as follows: .Persistence -> .Repo -> .Services -> .Controllers -> MVC3 App. Each layer has a respective assembly with interfaces and there's also some other assemblies like .Entities, .ViewModels, and common code assemblies. Persistence - This holds the EF4 datacontext (code-first) and a reference to EF4.3. There's a factory for creating the Context called GetContext() and this factory implements IDisposable. It is NOT a singleton cause I figured that's what

Identifying Relationship and inserting child entities causes “Cannot insert explicit value for identity column in table”

北慕城南 提交于 2019-12-07 08:35:36
问题 I am trying to get identifiying relationships to work in Entity Framework so I can remove items from their collection using Remove. I have created a test like: public class OrderLine{ [Key, Column(Order = 0)] public int OrderLineId { get; set; } [Key, ForeignKey("Order"), Column(Order = 1)] public int OrderId{ get; set; } public virtual Order Order{ get; set; } [ForeignKey("Product")] public int ProductId { get; set; } public virtual Product Product { get; set; } public int Number { get; set;

Is it acceptable to put seed data in the OnModelCreating method in EF code-first?

社会主义新天地 提交于 2019-12-07 07:57:12
问题 I know how to do seed data with the migrations API in EF 4.3. I've been playing with that all night. However, my ultimate goal is to get my project to the point where a user can pull it from source control and press F5 and they are good to go, database, seed data, and all. Currently code-first does an excellent job of building the DB on a fresh build but seed data isn't inserted until I do Update-Database in the package manager console. At that point it runs the seed method and inserts my

EF4.3.1 on .NET 4 - The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type

陌路散爱 提交于 2019-12-06 16:59:16
问题 Update: Subject updated - this is now reproducible on EF 4.3.1 under .NET 4 running with VS2012 installed under Windows 8. Any ideas why this would start happening now? The subject says it all really. We just upgraded from EF 4.3 code-first to EF 5 running under .NET 4.0. We have a query that looks similar to the following: ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray(); Entities.A is defined in an assembly called Entities and DTO.A is defined in an

Why does EF Code First [InverseProperty] attribute fail to work when used with [ForeignKey] attribute?

喜夏-厌秋 提交于 2019-12-05 22:46:21
Using: EF 4.3.1, Visual Studio 2010, SQL CE 4.0 My understanding is that when declaring Foreign Keys with DataAnnotation in EF, it can be done either of the following ways: Option 1- [ForeignKey("Player1Home")] public long? HPlayer1Id { get; set; } public virtual Player Player1Home { get; set; } Option 2- public long? HPlayer1Id { get; set; } [ForeignKey("HPlayer1Id")] public virtual Player Player1Home { get; set; } Problem: When the InverseProperty DataAnnotation gets used with Option 2 an extra column gets generated in the database (Player1Home_Id) in addition to HPlayer1Id. [Table("Matches"

Why are my EF Code First pregenerated views having no effect?

ⅰ亾dé卋堺 提交于 2019-12-05 20:33:26
问题 I have ~300 DbSets in my context and the first query after app load (a FirstOrDefault() where on an indexed field) takes ~40 seconds. To improve this, I am attempting to use pregenerated views in EF 4.3.1 Code First using the T4 template here: http://blog.3d-logic.com/2012/06/13/entity-framework-codefirst-view-generation-templates-on-visual-studio-code-gallery/ I compile it in, but I see no performance difference. I was hoping/assuming it would help the painful slow startup I am experiencing,

Identifying Relationship and inserting child entities causes “Cannot insert explicit value for identity column in table”

无人久伴 提交于 2019-12-05 18:00:02
I am trying to get identifiying relationships to work in Entity Framework so I can remove items from their collection using Remove. I have created a test like: public class OrderLine{ [Key, Column(Order = 0)] public int OrderLineId { get; set; } [Key, ForeignKey("Order"), Column(Order = 1)] public int OrderId{ get; set; } public virtual Order Order{ get; set; } [ForeignKey("Product")] public int ProductId { get; set; } public virtual Product Product { get; set; } public int Number { get; set; }} When I attempt to add a OrderLine like: var order=_orderRepository.Find(1); var NewOrderLine= new

Is it acceptable to put seed data in the OnModelCreating method in EF code-first?

吃可爱长大的小学妹 提交于 2019-12-05 09:04:06
I know how to do seed data with the migrations API in EF 4.3. I've been playing with that all night. However, my ultimate goal is to get my project to the point where a user can pull it from source control and press F5 and they are good to go, database, seed data, and all. Currently code-first does an excellent job of building the DB on a fresh build but seed data isn't inserted until I do Update-Database in the package manager console. At that point it runs the seed method and inserts my seed data. Is it okay to just do that in the OnModelCreating method? Can I still take advantage of the

Fetching complex objects by raw SQL query in Entity Framework

徘徊边缘 提交于 2019-12-05 07:32:31
I would like to fetch from database complex object using single query. Let's look at the following example: SELECT TableA.*, TableB.* FROM TableA INNER JOIN TableA.B_Id = TableB.Id and corresponding classes: public class QueryResult { public TableA A { get; set; } public TableB B { get; set; } } public class TableA { public int Id { get; set; } public string SomeContentA { get; set; } public int B_Id { get; set; } } public class TableB { public int Id { get; set; } public int SomeContentB { get; set; } } I would like to execute the raw SQL query from above against the database and get

Cannot update many-to-many relationships in Entity Framework

a 夏天 提交于 2019-12-05 06:04:39
I am using Entity Framework 4.3 Code First, and I have problem with updating many-to-many relationships. I defined the following classes: public abstract class Entity { [Column(Order = 0)] [Key] public int Id { get; set; } [Timestamp] [Column(Order = 1)] public byte[] Version { get; set; } } public class Video : Entity { public string Title { get; set; } public string Description { get; set; } public TimeSpan Length { get; set; } public virtual ICollection<Coworker> Coworkers { get; set; } } public class Coworker : Entity { public string FirstName { get; set; } public string LastName { get;