Linq 0..1-一关联

发布于 2024-10-19 23:56:31 字数 792 浏览 2 评论 0原文

嗨,我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲爱恨情仇 2024-10-26 23:56:31

典型的方法是使 TimePoint 的主键成为 Point 主键的外键。

The typical approach is to make TimePoint's primary key also be a foreign key to the Point's primary key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文