poco

POCO - if POCO means pure .net class with only properties, where i can write validations in MVC

寵の児 提交于 2019-12-19 11:59:11
问题 Very new to POCO, find some google links but found many different stories. Some connected with Entity framework, lazy loading etc. Some says its a pure .det class. Atleast MSDN. LINK FOR DEFINE POCO FROM MSDN: msdn.microsoft.com/en-us/library/dd456872.aspx I trust MSDN(a simple defination), and assume that it is a pure .NET Class. Now let me come to the point. IF it is pure .net class with only properties inside it than it is equilateral to "MODEL" in MVC. example. [Required(ErrorMessage =

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

EF 4.1: Removing child object from collection does not delete it - why?

强颜欢笑 提交于 2019-12-19 08:05:58
问题 I have a some error : EF 4: Removing child object from collection does not delete it - why? when i remove a child from the parent that the child is deleted when i call SaveChanges() , it gives the follow error message: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a

EF 4.1: Removing child object from collection does not delete it - why?

天涯浪子 提交于 2019-12-19 08:05:33
问题 I have a some error : EF 4: Removing child object from collection does not delete it - why? when i remove a child from the parent that the child is deleted when i call SaveChanges() , it gives the follow error message: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a

How do I use System.ComponentModel.DataAnnotations.AssociationAttribute

爷,独闯天下 提交于 2019-12-18 21:53:48
问题 Some time ago I asked this question: What is the purpose of each of the System.ComponentModel.DataAnnotations attributes? However, I had no luck with getting replies. This question was a bit broad in the sense that it asked for documentation about every dataannotation attribute. At this moment, I am mostly interested in the Association attribute. I am using ASP.NET MVC3 with Entity Framework 4 and would like to annotate my POCOs. I am using foreign keys in my POCOs (somehow feels wrong, but

Many-To-Many Relationship in Code-First EF4

时光毁灭记忆、已成空白 提交于 2019-12-18 11:56:38
问题 How do you represent a many-to-many relationship in the EF4 Code-First CTP3? For example if I have the following classes: class User { public int Id { get; set; } public string Name { get; set; } public ICollection<Profile> Profiles { get; set; } } class Profile { public int Id { get; set; } public string Name { get; set; } } In the database there is a UserProfiles table that has the FK for User and FK for Profile. How can I map this? EDIT: I understand how to to currently map with having a

EF Code First - Recreate Database If Model Changes

醉酒当歌 提交于 2019-12-18 10:55:18
问题 I'm currently working on a project which is using EF Code First with POCOs. I have 5 POCOs that so far depends on the POCO "User". The POCO "User" should refer to my already existing MemberShip table "aspnet_Users" (which I map it to in the OnModelCreating method of the DbContext). The problem is that I want to take advantage of the "Recreate Database If Model changes" feature as Scott Gu shows at: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework

OptimisticConcurrencyException Does Not Work in Entity Framework In Certain Situations

廉价感情. 提交于 2019-12-18 10:37:09
问题 UPDATE (2010-12-21): Completely rewrote this question based on tests that I've been doing. Also, this used to be a POCO specific question, but it turns out that my question isn't necessarily POCO specific. I'm using Entity Framework and I've got a timestamp column in my database table that should be used to track changes for optimistic concurrency. I've set the concurrency mode for this property in the Entity Designer to "Fixed" and I'm getting inconsistent results. Here are a couple of

Add property to POCO class at runtime

一个人想着一个人 提交于 2019-12-18 05:56:34
问题 I selected ServiceStack OrmLite for my project which is a pure Data-Oriented application. I am willing to allow the end user to create his own Object Types defined in an XML format that will be used to generate classes at runtime using CodeDOM. I will be also defining some "system" objects required by the application (i.e. User ) but I cannot foresee all the properties the end user will use and therefore I am looking for a way to allow extending the classes I create in design time. Sample

Entity Framework: Tracking changes to FK associations

送分小仙女□ 提交于 2019-12-18 01:21:36
问题 I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title