Linq 0..1-一关联
嗨,我在 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。 我所有的尝试都失败了。我不知道问题是出在 IsDbGenerate = true 还是其他方面。请帮忙。谢谢
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
{
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
典型的方法是使 TimePoint 的主键也成为 Point 主键的外键。
The typical approach is to make TimePoint's primary key also be a foreign key to the Point's primary key.