嗨,我对Linq有一个大问题。我必须做0。 这两个类中的.1对一关联:
[Table(Name = "TB_Points")]
public class Point
{
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; }
}
Point是我的通用类,因此有时候Point可以在没有TimePoint的情况下存在,因此关联中存在null。而且我不需要知道Point类中的TimePoint。 我所有的尝试都失败了我不知道问题是在IsDbGenerated = true还是在其他东西中。请帮忙。 THX
答案 0 :(得分:1)
典型的方法是使TimePoint的主键也成为Point主键的外键。