I met a problem when try to map an one-to-one relationship in a single table.
For example there're two entities (Product and ProductDetail):
public class Product
{
public virtual int ProductID { get; set; }
public virtual string Name { get; set; }
public virtual float Price { get; set; }
public virtual ProductDetail Detail { get; set; }
}
public class ProductDetail
{
public virtual int ProductID { get; set; }
public virtual Product Product { get; set; }
public virtual DateTime CreateTime { get; set; }
public virtual DateTime LastUpdated { get; set; }
}
And I'm going to put them in the same table as:
CREATE TABLE [dbo].[Product](
[ProductID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](128) NOT NULL,
[Price] [real] NOT NULL,
[CreateTime] [datetime] NOT NULL,
[LastUpdated] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED
(
[ProductID] ASC
))
I can only map to class into two separate table, what I'm going to do is put
this
new Product
{
Name = "123",
Price = 123.0,
Detail = new Detail
{
CreateTime = DateTime.Now,
LastUpdated = DateTime.Now,
}
}
like this:
ProductID Name Price CreateTime LastUpdated
1 123 123.0 2009:xx:xx 2009:xx:xx
Thanks
Jeffrey Zhao
Blog: http://www.cnblogs.com/JeffreyZhao
Twitter: http://twitter.com/jeffz_cn
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---