通过 Niberate、FluentNHibernate 映射主/详细信息场景中的问题

发布于 2024-11-28 19:29:03 字数 533 浏览 1 评论 0原文

我想实现以下要求:

编辑 我需要的是。可以有一个主位置和一个详细位置(一对多)。每个位置可以多辆车。主位置有自己的 carname(在 carname 表上)、cartext 和 IsCar(在 CarText 表上)。详细位置使用主位置中的 carname,但在 CarText 表上有自己的列。允许多个主位置(每个主位置有许多详细位置)。

我应该如何设计 Car 类以及 Fluent NHibernate 中的 ORM 映射?

以下是 C# 类:

Below is the tables:

    Table Location:
    LocationId

    Table CarName:
    CarId, LocationId, Name, Colour

The LocationId allows multiple cars. 

    Table CarText:
    CarTextId, CarId, LocationId, Text, IsCar

提前致谢!

I want to implement the following requirement:

Edit
What I need is. There can be one master location and detail locations (one-many). Each location can multiple cars. The master location has its own carname (on carname table), and cartext and IsCar(on CarText table). Detail location use carname from master location, but has its own columns on CarText table. Mutliple master locations are allowed (each master has many detail locations).

How should I design the Car class, and the ORM mapping in Fluent NHibernate??

Below is the C# classes:

Below is the tables:

    Table Location:
    LocationId

    Table CarName:
    CarId, LocationId, Name, Colour

The LocationId allows multiple cars. 

    Table CarText:
    CarTextId, CarId, LocationId, Text, IsCar

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蓬勃野心 2024-12-05 19:29:03

编辑:这个类结构更接近您的要求吗?

public class Location
{
    public virtual int Id { get; set; }
    public virtual Car MasterCar { get; set; }
}

public class Car
{
    public virtual Location Location { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<Location, string> TextsByLocation { get; set; }
}

编辑2:这样更好吗?

public class MasterLocation
{
    public virtual int Id { get; set; }
    public virtual ICollection<Location> Details { get; set; }
    public virtual string CarName { get; set; }
}

public class Location
{
    public virtual MasterLocation Master { get; set; }
    public virtual int Id { get; set; }
    public virtual ICollection<Cars> Cars { get; set; }
}

public class Car
{
    public virtual Location Location { get; set; }
    public virtual string Name
    {
        get { return Location.Master.CarName; }
        set { Location.Master.CarName = value; }
    }
    public virtual string Text { get; set; }
}

Edited: is this class structure nearer to your requirement?

public class Location
{
    public virtual int Id { get; set; }
    public virtual Car MasterCar { get; set; }
}

public class Car
{
    public virtual Location Location { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<Location, string> TextsByLocation { get; set; }
}

Edit2: this better?

public class MasterLocation
{
    public virtual int Id { get; set; }
    public virtual ICollection<Location> Details { get; set; }
    public virtual string CarName { get; set; }
}

public class Location
{
    public virtual MasterLocation Master { get; set; }
    public virtual int Id { get; set; }
    public virtual ICollection<Cars> Cars { get; set; }
}

public class Car
{
    public virtual Location Location { get; set; }
    public virtual string Name
    {
        get { return Location.Master.CarName; }
        set { Location.Master.CarName = value; }
    }
    public virtual string Text { get; set; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文