poco

Foreign Key To Microsoft.AspNet.Identity.EntityFramework.IdentityUser?

好久不见. 提交于 2019-12-28 16:05:43
问题 I'm in VS 2013 and have just created an MVC application. I'm creating an object I intend to have a foreign key to the AspNetUsers table in the resulting database. The project does have an ApplicationUser (deriving from IdentityUser) that looks like a property-column match with the AspNetUsers table. How do we properly declare a foreign key to this? public MyObject { public string UserId { get; set; } [ForeignKey("UserId")] public ApplicationUser User { get; set;} // other properties } Now, I

How to serialize/deserialize simple classes to XML and back

大憨熊 提交于 2019-12-27 17:38:11
问题 Sometimes I want to emulate stored data of my classes without setting up a round trip to the database. For example, let's say I have the following classes: public class ShoppingCart { public List<CartItem> Items {get; set;} public int UserID { get; set; } } public class CartItem { public int SkuID { get; set; } public int Quantity { get; set; } public double ExtendedCost { get; set; } } Let's say I build a ShoppingCart object in memory and want to "save" it as an XML document. Is this

How to Configure Entity Framework POCO with Similar Names

吃可爱长大的小学妹 提交于 2019-12-25 09:45:07
问题 I am working with EF4 with POCO objects I created. I have Customer entity in my model and two different classes from different projects: Domain.ProjA.Customer Domain.ProjB.Customer My code generation strategy of the EDMX file is Default. The POCO objects are in different project then the edmx. The edmx's project don't have refrence to the poco objects. How do I tell EF4 that Domain.ProjA.Customer is the POCO to the Customer entity? 来源: https://stackoverflow.com/questions/7839682/how-to

PoCo validation on Textbox for Integer DataType

浪尽此生 提交于 2019-12-25 08:39:36
问题 I am developing a WPF application in which i am using a textbox that is bind to an int field of my POCO entity, when i clear the textbox i want my currentobject to be invalid as this is a non nullable field. But the thing is when i clear my textbox, it convert to string.empty that can ot be set to an int value, so my int field never gets updated and my object remains Valid. Kindly suggest some logical solution to this. 回答1: One approach is to bind to a string value instead (probably added to

Creating Many-2-Many reference with EF

最后都变了- 提交于 2019-12-25 04:02:42
问题 In my current project (which is really small) i have 3 tables/ POCO entities which i would like to manipulate using EF. The Tables are: Status (contains status details) StatusStatusType (which is needed because of the many-2-many relationship) StatusType (A table which is used to group statuses by type) I now want to create a new Status in the database and user code like you see below //Create new status (POCO) entity var newStatus = new Status { StatusId = status.Id, UserId = user.Id, Text =

Get Name and Value of a property of a POCO object using an expression

主宰稳场 提交于 2019-12-24 12:51:48
问题 I'm looking for a way to get the name and value of a proptery in a POCO object. I've tried many solutions but can't seem to get them to work. I really liked this older solution but it causes a null ref error. Here's kind of what I'm trying to do: public class POCO { public int ID { get; set; } public string Name { get; set; } public string Surname { get; set; } public string Description { get; set; } } public class POCOValidationResult { public bool IsValid { get; set; } public string Error {

Load most recent related entity record on a list of entities in a single query

人盡茶涼 提交于 2019-12-24 12:00:34
问题 I am using Entity Framework 4.1 with POCOs and DbContext, no proxies no lazy loading. I am very new to Entity Framework and LINQ, but so far very impressed with how simple it is to work with it. I have some basic knowledge of SQL and have built the database first, and then created the model. My problem involves 3 tables (I only left in what is relevant): CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL ) CREATE TABLE [dbo].[UserFriends]( [UserId] [int]

How do I create a POCO object that has 2 references to another class

允我心安 提交于 2019-12-24 09:49:15
问题 I have a table (Event) that can have 2 Locations (main, alternate). Locations can be used in other tables (so no EventId in the locationTable) Using POCO self-tracking, how do I create the reference from the Event table to the Locations table, or what is the best way to handle this situation (I'm having a total brain freeze over this)? (.NET 4.0 C#, EF4.1, MVC 3 being used). Simplified classes: public class Event { public int EventId {get; set;} public string Tile {get; set;} public int

when to use the poco objects for views, and when the custom viewmodel classes

≯℡__Kan透↙ 提交于 2019-12-24 08:25:06
问题 Imagine that we have a poco that maps a table in a db. There are 15 fields in a poco, only 3 fields of 15 require the view. View display a list of records from db. Can I pass to the view list of poco's objects or I must to create a specific viewmodel class, init it and then pass to the view? I prefer the second variant, but is it good? Thanks. 回答1: Your inclination to the second approach is well founded. Creating and using viewmodels is the typical way for displaying data on View. In short,

EntityFramework CTP5 change tracking

假装没事ソ 提交于 2019-12-24 07:03:27
问题 I am trying to reproduce the same behavior as EntityObject using CTP5 DBContext for change tracking. Consider the tables Movie and Director. Relationship is only 1 director for a movie and multiple movies for each director. var movie = new Movie(); movie.Name = "ABCD"; ctx.Movies.Add(movie);//ctx.Movies.AddObject(movie); movie.Director = new Director() { Name = "dir1" }; var existingDirector = ctx.Directors.Where(a => a.Name == "dir2").FirstOrDefault(); movie.Director = existingDirector; ctx