entity-framework-4.1

MVC3 EF Unit of Work + Generic Repository + Ninject

女生的网名这么多〃 提交于 2019-12-01 05:30:51
问题 I'm new to MVC3 and have been following the awesome tutorials on the asp.net website. However, I can't quite wrap my head around how to use Unit of Work and Generic Repository patterns with Ninject. I used this tutorial as a starting point: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application Without using interfaces, I know I can implement it like so: Generic Repository: public class

ObjectSet.Context vs DbSet

时光怂恿深爱的人放手 提交于 2019-12-01 05:29:53
i used to use the ObjectSet in EF 4.0, I could get the underlying Context for this ObjectSet using myObjectSet.Context which returns ObjectContext . Now with DbSet in Ef4.1, what is the equivalent ?? EF 4.1 does not offer a public API to get the DbContext from the DbSet instance. You would have to use Reflections API to get the DbContext instance. Edit One workaround would be to pass around the DbContext instace with DbSet instance. Eg if you had a constructor that took only a DbSet instance. Pass the DbContext instace also. public MyService(DbContext context, DbSet<MyClass> mySet){} Other

Windows Azure with Multiple Sites in One Role not transforming 2nd web.debug.config to web.config

拈花ヽ惹草 提交于 2019-12-01 05:19:02
I am using Web.Config transformations to deploy my application to Azure. I also have 2 sites in my service, a public website, and private WCF site endpoint. I am deploying multiple sites to a single role . When I deploy, the website project (for which the Azure Deploy project is set) transforms the web.config correctly. However, the WCF project (which is only addressed as a "site" in the .csdef file) does not transform the web.debug.config file to web.config. This question is similar, but only addresses the projects building. I have set the dependencies in my project. This workaround forces

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

强颜欢笑 提交于 2019-12-01 04:12:36
I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without this, it appears incompatible with the T4 MVCScaffolding. Here are the details: Using the Entity Data Model Designer GUI, I have added a simple "country" table to the model from my existing database. The GUI correctly identifies a single integer identity key field named "PK" as my primary key. (Alas! I'm a new user so I can't add a screenshot. I've

EntityType 'ApplicantPosition' has no key defined

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:59:02
问题 When running my first asp.net mvc application I got this error I thought that entity framework automatically would create the keys of column names that end with Id? isnt it correct? As you can see the ApplicantPositionID would be a table with 2 columns as primary key because it would relate to Applicants and also to Position. One or more validation errors were detected during model generation: System.Data.Edm.EdmEntityType: : EntityType 'ApplicantImage' has no key defined. Define the key for

ObjectSet.Context vs DbSet

我的未来我决定 提交于 2019-12-01 03:34:02
问题 i used to use the ObjectSet in EF 4.0, I could get the underlying Context for this ObjectSet using myObjectSet.Context which returns ObjectContext . Now with DbSet in Ef4.1, what is the equivalent ?? 回答1: EF 4.1 does not offer a public API to get the DbContext from the DbSet instance. You would have to use Reflections API to get the DbContext instance. Edit One workaround would be to pass around the DbContext instace with DbSet instance. Eg if you had a constructor that took only a DbSet

Entity Framework foreign keys to non-primary key fields

眉间皱痕 提交于 2019-12-01 03:30:18
Is it possible for Entity Framework 4.0 to have an association/navigation property based off of a foreign key to a non-primary key field (it has a unique constraint). No because EF don't understand unique constraint yet and relations in EF must follow same rules as relations in database. Without unique principal relation cannot exist and the only way to get unique principal in EF is using primary key. 来源: https://stackoverflow.com/questions/9217448/entity-framework-foreign-keys-to-non-primary-key-fields

Reattaching an entity graph and detecting collection changes

送分小仙女□ 提交于 2019-12-01 03:27:00
问题 I'm using entity framework code first and exposing the northwind database through a WCF REST HTTP interface. I've not exposed the OrderDetails table (order items) as it doesn't make sense creating an order and then adding each required OrderDetail seperately through another service. To my mind it needs to be an atomic transaction that either succeeds or fails as one. Therefore I include the Order.OrderDetails collection when passing to the client and assume I'm going to get one when an order

Difference between DbSet.Remove and DbContext.Entry(entity).State = EntityState.Deleted

烈酒焚心 提交于 2019-12-01 03:26:48
Consider the following entity model: public class Agreement : Entity { public int AgreementId { get; set; } public virtual ICollection<Participant> Participants { get; set; } } public class Establishment : Entity { public int EstablishmentId { get; set; } } public class Participant : Entity { public int AgreementId { get; set; } public virtual Agreement Agreement { get; set; } public int EstablishmentId { get; set; } public virtual Establishment { get; set; } public bool IsOwner { get; set; } } The reason there is not a direct ICollection<Establishment> on the Agreement entity is because of

Windows Azure with Multiple Sites in One Role not transforming 2nd web.debug.config to web.config

旧巷老猫 提交于 2019-12-01 02:55:38
问题 I am using Web.Config transformations to deploy my application to Azure. I also have 2 sites in my service, a public website, and private WCF site endpoint. I am deploying multiple sites to a single role. When I deploy, the website project (for which the Azure Deploy project is set) transforms the web.config correctly. However, the WCF project (which is only addressed as a "site" in the .csdef file) does not transform the web.debug.config file to web.config. This question is similar, but only