Linq 0..1-one association
Hi I have a big problem with Linq. I have to do a 0. .1-to-one association within this two classes:
[Table(Name = "TB_Points")]
public class Point
{
开发者_StackOverflow private int _ID = 0;
[Column(Storage = "_ID", DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get { return this._ID; } }
}
[Table(Name = "TB_TimePoint")]
public class TimePoint
{
private int _ID = 0;
[Column(Storage = "_ID", DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get { return this._ID; } }
//here is the association
public Point Pos { get; set; }
}
The Point is a my general class so some times a Point can exists without the TimePoint, so there is null in the association. And I don't need to know about the TimePoint from the Point class. All my attempts failed. I don't know whether the problem is in IsDbGenerated = true or in other stuff. Please help. Thx
The typical approach is to make TimePoint's primary key also be a foreign key to the Point's primary key.
精彩评论