poco

AutoMapper, how to keep references between mapped objects?

爱⌒轻易说出口 提交于 2019-12-10 13:40:10
问题 I am using AutoMapper to convert a UI model to POCOs that I later serialize to XML using a DataContractSerializer in order to preserve the references between them. The problem comes that, when mapping, the references between those entities are lost . The UI classes reference each other, but the mapping process makes new instances for every reference, so the original relations are broken :( Let me explain: I have 2 entities of type Person Person { List<House> OwnedHouses } And these 2 objects

Entity Framework 4.1 DbContext generator problems

。_饼干妹妹 提交于 2019-12-10 11:32:42
问题 I am new to Entity Framework 4.1 and I really wanted to transition to POCO classes for my model. I found that this was very easy using the "DbContext Generator" item provided when you install EF 4.1. It did exactly what I wanted it to do and generated the DbContext object and all the POCOs for my existing EDMX model. I ran the app and tested that it was still working. It was. Happy with this I deleted the EDMX file and the T4 templates and began reorganizing my new POCOs. However, after

What is the best practice to deal with navigation properties when using DTO and POCO objects?

ⅰ亾dé卋堺 提交于 2019-12-10 01:54:59
问题 I'm trying to wrap my head around Domain Driven Development. I want to make sure I have a good foundation and understanding of it, so it would be great if recommendations to use AutoMapper or similar are avoided here. My architecture currently involves the following: The WCF service is responsible for persistence (using Entity Framework) and server-side validation. It converts POCO's to DTO's, and DTO's are transferred to the client. The Client, receives DTO's and converts them to POCO's. The

Custom setter for C# model

我只是一个虾纸丫 提交于 2019-12-10 00:55:19
问题 I don't know how to make custom setter for C# data model. The scenario is pretty simple, I want my password to be automatically encrypted with SHA256 function. SHA256 function works very well (I've used in in gazillion of projects before). I've tried couple of things but when I run update-database it seems it's doing something recursively and my Visual Studio hangs (don't send error). Please help me understand how to make passwords be encrypted by default in model. Code with what I've already

Entity with many-to-many relationship creation fails after upgrading to RC

最后都变了- 提交于 2019-12-09 20:57:03
问题 I've got a project with 3 simple tables, a couple of POCO classes, and a DBContext created with code, no edml file. The following code setup used to work with the beta of Entity Framework code-first, I've edited the DbContext code since the ModelBuilder changed from the beta to RC Tables (simple tables many-to-many table has fields declared as foreign keys with cascade deletion): CREATE TABLE [dbo].[Bookings]( [ID] [int] IDENTITY(1,1) NOT NULL, [StartDate] [datetime] NOT NULL, [EndDate]

Adding methods to POCO classes

折月煮酒 提交于 2019-12-09 18:20:15
问题 I have the following setup: MVC > Services > Repositories. Now I want to allow users to be able to add a Note to a Document. Only Users associated with the Document (either as owners or reviewers) can add Notes so in my NoteService I do the following to ensure the User has permission on the selected Document: public Note GetNewNote(int documentID) { if (!userHasAccess(Thread.CurrentPrincipal.Identity.Name)) throw new BusinessLogicException(); // Other stuff here... } My question is, where

What are essential differences between the different code generation items for EDMX model?

最后都变了- 提交于 2019-12-09 09:10:45
问题 I'm trying to ramp up on the entity framework so I don't feel like I'm in the dark ages. I tried (and have thus far failed) to intuit from generated code what the essential differences between the available code generation items. It seems POCO isolates the entity data structures from the ojbect that moves them in/out of a datastore. I'm not sure what a "Self-Tracking Entity" is. I'm guessing the tracking part refers realizing the so called "unit of work" pattern, but I'm not posative. And

Entity Framework in Layered Architectures

淺唱寂寞╮ 提交于 2019-12-09 04:50:32
问题 Recently I've read article "The Entity Framework In Layered Architecture" and there is written we can send EF-entities to client through WCF. But in many threads on Stackoverflow people tell that POCO(DTO)-objects should be used when we use WCF. And I have some questions. Why did Microsoft add DataContract attribute to EF-entities? Does Microsoft wanted us to use these objects everywhere in our applications? Or this is only for very simple applications and for rapid development? If I use POCO

POCOs and multiple ViewModels pointing to the same POCO?

こ雲淡風輕ζ 提交于 2019-12-09 04:38:41
How would one go about handling a situation like this? Having more than one ViewModel having a reference to the same POCO object. ViewModel A updates the POCO... now ViewModel B needs to know about this somehow? Assuming that your POCO can't implement INotifyPropertyChanged , you could use a mediator pattern to alert other view models when a POCO is changed: public interface ICareWhenAModelChanges<T> { void ModelUpdated(T updatedModel); } public class ModelChangeMediator<T> { private List<ICareWhenAModelChanges<T>> _listeners = new List<ICareWhenAModelChanges<T>>(); public void Register

Handle Entity Framework On Create POCO

≯℡__Kan透↙ 提交于 2019-12-09 02:53:30
问题 I'd like to see if there's a way to hook into the Entity Framework context so I know as soon as it has finished creating a POCO object. Are there any attributes I can use, such as with [OnDeserializing]? The purpose is to set a few values on the object as soon as the context is done creating it from a database fetch. Thanks very much. 回答1: Hook into the ObjectMaterialized event fired by ObjectContext. In CTP5, you need to cast your DbContext like so in the constructor for your DbContext: (