entity-framework-4.1

Entity Framework 4.1 reverse engineering code-only

跟風遠走 提交于 2020-01-23 12:12:15
问题 I am using Entity Framework 4.1 and want to take advantage of their code-only approach. In the video located at http://channel9.msdn.com/Events/TechEd/Europe/2010/DEV212 starting at 35:00 minutes in they show a tool that reverse engineers their POCOs from their existing database. I want to do this as I have an existing database. I have installed EF 4.1 and I can create POCO entities just fine but I can't seem to find the tool they used to create POCOs from the existing database. Was this tool

Entity framework data contract

醉酒当歌 提交于 2020-01-23 10:46:48
问题 I am new to WCF and Entity framework. I have a class library "A" which contains DatabaseEntities.edmx (Entity Framework objectContext ). This library is exposing a class "B" which contains a function FunctionB , internally using the entity objects. I have taken this library "A" reference into a WCF web service and inside the IService.cs - I have coded it like this: [OperationContract] void FunctionB_Proxy(); Without defining any DataContract I have gone into Service1.cs and implemented this

Entity framework data contract

做~自己de王妃 提交于 2020-01-23 10:46:12
问题 I am new to WCF and Entity framework. I have a class library "A" which contains DatabaseEntities.edmx (Entity Framework objectContext ). This library is exposing a class "B" which contains a function FunctionB , internally using the entity objects. I have taken this library "A" reference into a WCF web service and inside the IService.cs - I have coded it like this: [OperationContract] void FunctionB_Proxy(); Without defining any DataContract I have gone into Service1.cs and implemented this

Property with StoreGeneratedPattern set to Identity is not updted after SaveChanges()

╄→尐↘猪︶ㄣ 提交于 2020-01-17 07:30:13
问题 I have a method which writes log information in Db. This method is called in a loop. On the second insert I get the InvalidOperationException: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique

Entity Framework Model Property not update properly

柔情痞子 提交于 2020-01-16 19:13:06
问题 I am having below mentioned 2 models. GeoLocation Model : public class GeoLocation { public GeoLocation() { } public int Id { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } } Provider Model : public class Provider { public Provider() { Id = Guid.NewGuid(); Created = DateTime.Now; } public Guid Id { get; set; } [Required] public string Name { get; set; } public virtual GeoLocation Location { get; set; } } Repository method : public void SetLocation

Entity Framework 4.1 and OriginalValues/CurrentValues and DbContext

橙三吉。 提交于 2020-01-16 15:22:31
问题 I'm currently using DbContext with Ef 4.1, and I'm trying to audit all changes some of my entities. I can capture the original and current values for any Properties of an entity, however I cannot figure out how to capture the association (Foreign Key) OriginalValues of a NavigationProperty. Has anyone figured this out? 回答1: You must either include foreign keys to your entities so they will be tracked as normal values or you must convert your DbContext to ObjectContext and use more powerful

One to Many with Entity Framework not updating the foreign key

夙愿已清 提交于 2020-01-15 09:05:32
问题 I need some help, I have been searching everywhere for ages to why this keeps happening. I basically have 2 tables, Company and Address. A company can have multiple addresses. My classes and tables look like the following TABLES: create table Company ( companyid int PRIMARY KEY IDENTITY not null, name varchar(100), agencyref varchar(20), website varchar(100), phoneno varchar(20), faxno varchar(20), modified datetime DEFAULT (GETDATE()) ); create table Address ( addressid int PRIMARY KEY

Targetting x64 platform with entity framework 4.1 in Visual Studio 2010

血红的双手。 提交于 2020-01-15 03:18:07
问题 I have a database application that references Entity Framework 4.1. In the properties window of the project both the Configuration as well as Platform selection options are disabled. I wan't to target this application only for x64 systems. Also there are some other projects in the same Solution and they have only x86 option avaliable as platform. I don't get the idea why I couldn't target x64 systems specifically. I have windows 7 64 bit running on my pc. Any clues how to target specifically

Specify a cascading delete for parent / child relationships?

房东的猫 提交于 2020-01-14 19:23:28
问题 Model: public class MenuItem { public Guid Id {get;set;} public virtual Guid? ParentMenuItemId {get;set;} public virtual MenuItem ParentMenuItem {get;set;} public virtual ICollection<MenuItem> ChildMenuItems {get;set;} } current mapping: HasOptional(m => m.ParentMenuItem).WithMany(p => p.ChildMenuItems).HasForeignKey(m => m.ParentMenuItemId); I tried adding the WillCascadeOnDelete(true) , but I got an error. How should I update my mapping to allow for cascading deletes? So, If I delete a

How to observe the Add action of DbSet<T>?

試著忘記壹切 提交于 2020-01-13 10:05:26
问题 I has two classes named Contact and ContactField as following. When the ContactField is added into Contact , I hope to assign SortOrder to ContactField automatically. Do I need to inherit DbSet and customize the Add method ? How to achieve it ? public class Foo { private MyDbContext _db = new MyDbContext(); public void HelloWorld() { Contact contact = ....; //< A contact from database. ContactField field = ....; ///< A new field .... ///< assign other properties into this `field` field