poco

Entity framework attach update not working

Deadly 提交于 2019-12-04 16:51:17
问题 I'm trying to update a POCO object using entity framework in the following way: context.Jobs.Attach(job); context.SaveChanges(); That does not work. No error is thrown, it just isn't updating the values in the database. I tried: context.Jobs.AttachTo("Jobs", job); context.SaveChanges(); Nothing wrongs, still no error and no updates. 回答1: What about changing the ObjectState ? context.ObjectStateManager.ChangeObjectState(job, System.Data.EntityState.Modified); From MSDN: ObjectStateManager

Entity Framework Service Layer Update POCO

南楼画角 提交于 2019-12-04 16:38:51
I am using the Service Layer --> Repository --> Entity Framework (Code-First) w/POCO objects approach, and I am having a hard time with updating entities. I am using AutoMapper to map my Domain Objects to my View Models and that works good for getting the data, no how do I get that changes back into the database? Using pure POCO objects, I would assume that there is no sort of change tracking, so I see my only option is to handle it myself. Do you just make sure that your View Models have the EXACT same properties as your Domain Objects? What if I just change a field or two on the View Model?

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

喜欢而已 提交于 2019-12-04 14:41:23
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] [datetime] NOT NULL, [AccountId] [varchar](50) NOT NULL, CONSTRAINT [PK_Bookings] PRIMARY KEY CLUSTERED (

Using Data Annotations on POCO's with MVC for Remote Validation

你说的曾经没有我的故事 提交于 2019-12-04 13:51:46
问题 I am developing an ASP.NET MVC app and I've been looking into using Data Annotations on my POCO's which are defined in my Service Layer. As long as I have a reference to System.ComponentModel & System.ComponentModel.DataAnnotations this is no problem and what I like about this is that it allows me to reuse my Service Layer in a Win Forms app. I'm now looking to do some Remote Validation using Data Annotations and have taken a look at this article: http://msdn.microsoft.com/en-us/library

Exception during association fixup with nullable composite foreign keys

狂风中的少年 提交于 2019-12-04 13:13:43
问题 I have a problem with Pocos and nullable foreign keys . I have 2 tables (orders and products) each table have a composite primary key (orderid,orderid2) and (productid,productid2) And I have set a 0,1..* association between the two tables. One order can be related to 0 or 1 product. And one product has * orders related to him. How to crash : Create a new product using CreateObject(). Add the new product to then entityset. Create a new order usung CreateObject(). Add the new Order to the

Entity Framework classes vs. POCO

*爱你&永不变心* 提交于 2019-12-04 05:36:40
I have a general difference of opinion on an architectural design and even though stackoverflow should not be used to ask for opinions I would like to ask for pros and cons of both approaches that I will describe below: Details: - C# application - SQL Server database - Using Entity Framework - And we need to decide what objects we are going to use to store our information and use all throughout the application Scenario 1: We will use the Entity Framework entities to pass all around through our application, for example the object should be used to store all information, we pass it around to the

Do we need DataContract attribute on POCO classes in Ado.net entity Framework 2010

£可爱£侵袭症+ 提交于 2019-12-03 20:58:41
I read somewhere in stackoverflow itself that when we use POCO classes for WCF contracts using Poco generator , we need not use DataContract and DataMember attributes.WCF do it auto for you? . I don't know how it manages this. I created a sample application without using these attributes and I was able to generate those entities on client side and use them. I disabled proxy generation and Lazy loading. Am i missing anything here.? Is there really no need of putting these attributes. You did it right way. Since WCF 3.5 SP1 it is not needed to add DataContract and DataMember attributes. If

Are code generators bad?

断了今生、忘了曾经 提交于 2019-12-03 15:44:40
问题 I use MyGeneration along with nHibernate to create the basic POCO objects and XML mapping files. I have heard some people say they think code generators are not a good idea. What is the current best thinking? Is it just that code generation is bad when it generates thousands of lines of not understandable code? 回答1: Code generated by a code-generator should not (as a generalisation) be used in a situation where it is subsequently edited by human intervention. Some systems such the wizards on

Loading from database without proxy classes?

南楼画角 提交于 2019-12-03 13:29:28
In Entity Framework 4 Is it possible to choose to load some queries into a POCO without it using proxy classes? (For the purpose of caching that object for future read only use). I am using the Repository - Service pattern. By this I mean: var order = _orderService.GetById(1); // after order is loaded then we can see in the debugger that: // order.Customer is of type System.Data.Entity.DynamicProxy.Customer_17631AJG_etc What I want is for the order.Customer to actually use the POCO type MyApp.Models.Entities.Customer instead of a proxy to that type. EDIT: Based on Ladislav's suggestion to add