poco

EF4 Cast DynamicProxies to underlying object

↘锁芯ラ 提交于 2019-11-27 14:39:30
问题 I'm using Entity Framework 4 with POCO template. I have a List where MyObject are dynamic proxies. I want to use the XmlSerializer to serialize this list, but I don't want them serialized as DynamicProxies but as the underlaying POCO object. I know about ContextOptions.ProxyCreationEnabled, but I do not want to use that. I just want to know how to cast a proxy object to it's underlaying POCO to serialize. 回答1: Faced the same issue today and used Value Injecter to solve it. It's as simple as:

Entity Framework 5 - How to generate POCO classes from existing database

谁说胖子不能爱 提交于 2019-11-27 13:50:59
问题 I am using VS 2012 and EF 5. I have an existing database that I want to create POCO classes from the existing database. I followed the steps to add an ADO.NET Entity Data Model to my project. I went through the wizard to use an existing database. It then created the edmx and tt files with the designer open. However, I want to create the POCO objects and use them. The Microsoft site states that the POCO Entity Framework Generator is obsolete and I should use the DBContext Generator. I can't

What exactly is “persistence ignorance”?

做~自己de王妃 提交于 2019-11-27 12:20:42
Persistence ignorance is typically defined as the ability to persist & retrieve standard .NET objects (or POCOs if you really insist on giving them a name). And a seemingly well accepted definition of a standard .NET object is: "...ordinary classes where you focus on the business problem at hand without adding stuff for infrastructure-related reasons..." However, I see people describing NHibernate as a framework that allows persistence ignorance, and yet it is a framework that cannot work on any standard .NET object, only standard .NET objects that adhere to particular design requirements, for

what is Entity Framework with POCO

折月煮酒 提交于 2019-11-27 10:30:50
问题 What is the benefit of using POCO? I don't understand the meaning of Persistence Ignorance, what does this mean? That the poco object can't expose things like Save? I can't wrap my head around this POCO that there's alot of buzz around. What is the difference with the EF generated entities and POCO? 回答1: POCO stands for "Plain Old C# Object" or "Plain Old CLR Object", depending on who you ask. If a framework or API states that it operates on POCO's, it means it allows you to define your

Is it possible to prevent EntityFramework 4 from overwriting customized properties?

天涯浪子 提交于 2019-11-27 08:05:42
I am using EF 4 Database first + POCOs. Because EF has no easy way to state that incoming DateTimes are of kind UTC, I moved the property from the auto-generated file to a partial class in another file. private DateTime _createdOn; public virtual System.DateTime CreatedOn { get { return _createdOn; } set { _createdOn = (value.Kind == DateTimeKind.Unspecified) ? _createdOn = DateTime.SpecifyKind(value, DateTimeKind.Utc) : value; } } However, now every time I update the model, the automated properties get created again in the T4-generation. Of course this causes the following compilation error:

Why is my Entity Framework Code First proxy collection null and why can't I set it?

天大地大妈咪最大 提交于 2019-11-27 06:48:34
I am using DBContext and have two classes whose properties are all virtual. I can see in the debugger that I am getting a proxy object when I query the context. However, a collection property is still null when I try to add to it. I thought that the proxy would ensure that collection is initialized. Because my Poco object can be used outside of its data context, I added a check for the collection being null in the constructor and create it if necessary: public class DanceStyle { public DanceStyle() { if (DanceEvents == null) { DanceEvents = new Collection<DanceEvent>(); } } ... public virtual

What is the proper data annotation to format my decimal property?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 06:36:53
问题 I have a POCO with a decimal property called SizeUS. I would like to use data annotations to format the display of the decimal in a view. My SizeUS property is only displaying 2 decimal places in my view and I want it to display 4 decimal places. What is the proper data annotation to accomplish this ? [DisplayFormat( ? )] public decimal SizeUS {get; set;} 回答1: [DisplayFormat(DataFormatString="{0:#.####}")] See Custom Format Strings for formats and DisplayFormatAttribute for examples 来源: https

POCO's, behavior and Peristance Igorance

亡梦爱人 提交于 2019-11-27 05:29:29
From what I have read POCO classes should be persistence ignorant and should not contain references to repositories. Q1. Given the above, how would I populate the QuestionBlocks collection? I have read that POCO's should contain behavior so you don't end of with an anemic model, so I'm kind of confused as how one is supposed to do that without persistence. If that's the case then what kind of behavior would you put in a POCO? Ex: public class Survey { public int SurveyId { get; set; } public string Title { get; set; } public int BrandId { get; set; } public DateTime Created { get; set; }

Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

亡梦爱人 提交于 2019-11-27 05:16:52
问题 I am having an issue using AutoMapper (which is an excellent technology) to map a business object to a DTO where I have inheritance off of an abstract base class within a collection. Here are my objects: abstract class Payment class CashPayment : Payment class CreditCardPayment : Payment I also have an invoice object which contains a collection of payments like so: public class Invoice { ... properties... public ICollection<Payment> Payments { get; set; } } I also have corresponding DTO

Entity Framework Eager Load Not Returning Data, Lazy Load Does

陌路散爱 提交于 2019-11-27 04:33:52
问题 I'm using code first EF5 and I have an object which has a collection defined as virtual (lazy loaded). This returns data when called. However I want it to be eager loaded. I've removed virtual from the property signature but now it always returns null data. EF doesn't even run the query , can anyone help? Edit: I know about .include() I'd just prefer to use the non-virtual property method of doing it. Objects User ( [Key] Id is on Resource object which is the Parent of person class):