poco

Programmatically obtain Foreign keys between POCOs in Entity Framework 6

不羁的心 提交于 2019-12-01 23:22:39
I am faced with an EF6 Code First context, with a few DbSet s of POCOs that have navigation properties (and foreign keys) between them, e.g.: public partial class Person { public Guid Id { get; set; } public virtual ICollection<Address> Address { get; set; } } public partial class Address { public Guid Id { get; set; } public Guid FK_PersonId { get; set; } public virtual Person Person { get; set; } } modelBuilder.Entity<Person>() .HasMany (e => e.Address) .WithRequired (e => e.Person) .HasForeignKey (e => e.FK_PersonId) .WillCascadeOnDelete(false); Given these types, is there any proper way (i

EF6 POCO INotifyPropertyChanged without viewmodels

為{幸葍}努か 提交于 2019-12-01 21:57:25
I have been binding in WPF application directly to the model classes (and skipping creating individual viewmodel classes). Now, after switching to EF6 and DBContext, I face an issue with the generated EF POCO classes since it looks its either kind of tricky or not even recommended trying to make INotifyPropertyChanged interface implemented directly to those classes. Currently: I don't want to go back to ObjectContext. I don't want to change T4 too much either. The suggestions on the web for changing T4 to achieve INotifyPropertyChanged looks too error-prone for me. Creating viewmodels for each

Data access layer design in DDD

馋奶兔 提交于 2019-12-01 18:44:35
Excuse me for my poor English. Ok, I'm thinking about DDD approach now and it sounds great but... There is one little question about it. DDD says that the domain model layer is totally decoupled from the data access layer (and all other layers). So when the DAL will save some business object it will have access to public properties of this object only. Now the question: How can we guarantee (in general) that a set of public data of an object is all we need to restore the object later? Example We have the following business rules: User and domain must be provided for the business object on

Private constructor on POCO entity preventing lazy loading

和自甴很熟 提交于 2019-12-01 16:36:02
问题 I have a POCO entity on which I have defined a custom constructor. I have also implemented the default constructor so that Entity Framework can successfully hydrate the object when I request a copy from the database. This seems to work well but when I set the default constructor to private (to force my code to use the custom version) and request an entity from the database, I don't seem to be able to navigate over related entities as they are all null. This seems to be a lazy loading problem

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

只愿长相守 提交于 2019-12-01 14:45: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 PrivilegeGroup { public int PrivilegeGroupID { get; set; } public string Name { get; set; } public List<User> Users

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

亡梦爱人 提交于 2019-12-01 14:07:25
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 = "Full Name required.")] [StringLength(20, ErrorMessage = "Username must be under 20 chars.")] public

Load JSON data stream from text file into objects C#

家住魔仙堡 提交于 2019-12-01 12:02:09
问题 I'm using Newtonsoft.Json.Linq and I'd like to load the data into objects (or structs) that I define and put the objects into a list or collection. Currently I'm pulling out the JSON properties with indexes to the names. filename = openFileDialog1.FileName; StreamReader re = File.OpenText(filename); JsonTextReader reader = new JsonTextReader(re); string ct = ""; JArray root = JArray.Load(reader); foreach (JObject o in root) { ct += "\r\nHACCstudentBlogs.Add(\"" + (string)o["fullName"] + "\",\

Generate POCO classes from model using T4 templates vs. EF4.1 simplified API Model First approach

╄→гoц情女王★ 提交于 2019-12-01 06:58:07
问题 I have model created with visual designer. Now I want to have POCO classes generated from it. In another question of mine, EF4.1 simplified API Model First approach was suggested to me. Before I was also thinking about T4 templates. What are the limitation of EF4.1 simplified API Model First comparing to using T4 templates to generate POCO classes ? What are advantages to of EF4.1 approach if any (besides it is supposed to be simpler to use)? My decision now will be very hard to undone as I

Entity Framework & Self-Tracking Entities vs POCO

大憨熊 提交于 2019-12-01 06:41:40
If i'm wanting to use entity framework 4 as my data layer and want to send my entities to another tier whether it be via WCF or another mechanism and then want the ability to update the entities and send them back for updating/deleting/inserting is it best to use self-tracking entities or poco objects? I'd rather use POCO objects if possible because i don't want to depend on the entity framework in the other layers if possible but i don't know how difficult it is to reconnect POCOs to the context. Ladislav Mrnka This is combination of too many questions and most of them were already asked on

EF4 Code First - How to properly map Splitting an Entity Across Multiple Tables

被刻印的时光 ゝ 提交于 2019-12-01 05:55:46
I am using EF4 CTP5 to try to persist a POCO object that is split among two tables, the link being the ContactID. When i save a contact, i want the core contact information saved in one table (Contacts), and the link to the user who owns the contact saved in another (UserToContacts). I have the custom mapping defined below, but when I SaveChanges, i get the following error: A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple store-generated columns. Any ideas would be greatly appreciated! protected