entity-framework-4

Entity Framework: how to do correct “Include” on custom type

北城余情 提交于 2019-12-20 00:52:52
问题 Suppose we have 2 types, mapped to a Database via EF 4. Schedule 1.....1 Visit Also, we have third custom view type public class ScheduleView { public Schedule Schedule { get; set; } public Visit Visit { get; set; } } So we can write the join query var query = Context.Schedule.Join(Context.Visit ,/*Schedule join key definition*/,/*Visit join key definition*/, (scheduleView, visit) => new ScheduleView {Schedule = scheduleView, Visit = visit}) The problem is that I need to load also Patient

Update part of primary key Entity Framework 4.0

别等时光非礼了梦想. 提交于 2019-12-19 18:38:12
问题 I've a table with a compose primary key (3 columns): UTP_ID (ITEMId) UTS_ID (CategoryID) USS_ID (SubCategoryID) When I try to change SubCategory ,for example,with EF 4 i get follow error: utl.USS_ID = Convert.ToInt32(ddlSubSetor.SelectedItem.Value); the property is part of the object's key information and cannot be modified Any Ideias?Why i can't change it? 回答1: EF implements an Identity Map between primary key property values and object references. It doesn't allow to change the key for the

Update part of primary key Entity Framework 4.0

我的未来我决定 提交于 2019-12-19 18:37:06
问题 I've a table with a compose primary key (3 columns): UTP_ID (ITEMId) UTS_ID (CategoryID) USS_ID (SubCategoryID) When I try to change SubCategory ,for example,with EF 4 i get follow error: utl.USS_ID = Convert.ToInt32(ddlSubSetor.SelectedItem.Value); the property is part of the object's key information and cannot be modified Any Ideias?Why i can't change it? 回答1: EF implements an Identity Map between primary key property values and object references. It doesn't allow to change the key for the

How to delete entity in many-to-many relationship using POCOs

筅森魡賤 提交于 2019-12-19 11:57:32
问题 I'm using POCOs in combination with EF4 and some entities are in many-to-many relationships, in my case objects of class User and objects of class PrivilegeGroup. This is how class User looks like: public class User { public int UserID { set; get; } public string UserName { get; set; } public string UserPassword { get; set; } public bool IsActive { get; set; } public List<PrivilegeGroup> PrivilegeGroups { get; set; } } And this is how class PrivilegeGroup looks like: public class

Problems trying to attach a new EF4 entity to ObjectContext while its entity collection entities are already attached

寵の児 提交于 2019-12-19 11:47:14
问题 This is somewhat complicated to explain, so please bear with me. I have an ASP.NET MVC 2 project that is slowly killing me in which I'm trying to take form data and translate it into entities to create or update, depending on the context of the situation. The most relevant parts (pseudo-code): Entity Game Scalar properties EntityCollection<Platform> Platforms And the basic workflow is: Form data -> model bound to a DTO -> mapping the DTO to an EF4 entity with AutoMapper. It all works well

When working with Entity Framework, is it possible to force generated entity classes to be Pascal case?

谁都会走 提交于 2019-12-19 11:45:11
问题 The database I'm working against has table names such as "table_name". That's fine, but I'd like to generate classes in the format "TableName" to work with in C#, Pascal style. Is this possible? 回答1: Update: For use with EF6, see additional answer on this page. Thanks to Alex's answer, I've now extended this code to a full working solution that solves this problem. Since it's taken me most of the day, I'm posting here to help others facing the same challenge. This includes a complete class

Can a class inherit from Entity Framework class and still persist back to the DB using the inherited classes mappings?

偶尔善良 提交于 2019-12-19 11:24:49
问题 Can a class inherit from Entity Framework class and still persist back to the DB using the inherited classes mappings? I have received errors trying to derive from a 'Self-Tracking Entity' class when I try and SaveChanges stating that the Type does not have any mappings. I would have hoped since the Type was Inherited from the Entity class that it could also inherit the entity mappings somehow for this to work. Has anyone been able to get this to work? The scenario I am trying to support is

WCF data serialization : can it go faster?

穿精又带淫゛_ 提交于 2019-12-19 10:44:13
问题 This question is sort of a sequel to that question. When we want to build a WCF service which works with some kind of data, it's natural that we want it to be fast and efficient. In order to achieve that, we have to make sure all segments of data road trip work as fast as they could, from data storage back-end such as SQL Server, to a WCF client who requested that data. While seeking for an answer on that previous question, we have learned, thanks to Slauma and others who contributed through

Implementing identifying relationships with EF4

扶醉桌前 提交于 2019-12-19 10:34:13
问题 I'm currently in a situation where I need to delete entities without having access to the associated ObjectContext . I read about identifying relationships and they seem to be exactly what I need: I want to delete an object, once it is no longer referenced by its "parent" object. I am using Visual Studio 2010 Premium to generate my database from an edmx file. As far as I understand, I need to include the foreign key of my "parent" object in the primary key of my "child" object table. However,

Eagerly Load Navigation Property that is List<OfSomeBaseClass>

不想你离开。 提交于 2019-12-19 10:26:32
问题 Using EF Code First and given an Entity that contains a List, how can I eagerly load the entire object graph for that entity: Example: public class Foo { public int Id { get; set; } public List<BarBase> Bars { get; set; } } public class BarBase { public int Id { get; set; } public string Text { get; set; } } public class BarTypeA : BarBase { public List<Baz> Bazes { get; set; } } public class BarTypeB : BarBase { public List<Quux> Quuces { get; set; } { get; set; } } If BarBase were not a