Fluent NHibernate 映射问题

发布于 2024-11-29 05:25:30 字数 1370 浏览 1 评论 0原文

我有以下类和表,我想了解如何在 Fluent Nhibernate 中映射它:

class File
        {
            public virtual int Id { get; set; }
            public virtual IList<FileParameter> FileParameters { get; set; }
            public virtual IList<File> DetailFile { get; set; }
        }

        class FileParameter
        {
            public virtual int Id { get; set; }
            public virtual File MasterFile { get; set; }
            public virtual string Name { get; set; }
            public virtual string DisplayName { get; set; }

            public virtual FileParameterValue FileParameterValue { get; set; }

        }

        class FileParameterValue
        {
            public virtual int Id { get; set; }
            public virtual File ParentFile { get; set;}
            public virtual FileParameter FileParameter { get; set; }
            public virtual string DefaultValue { get; set; }
            public virtual bool DisplayStatus { get; set; }
        }

数据库表

Table File
FileId, 

Table FileParameter
ParameterId, FileId, Name, DisplayName

Table FileParameterValue
FileParameterValueId, ParameterId, FileId, DefaultValue, DisplayStatus

我想要实现的是,有一个主文件及其许多详细信息文件。每个主文件都有自己的 FileParameter 和 FileParameValue。主文件的每个子文件都使用主文件的 FileParameter,但具有自己的 FileParameterValue。

任何理想都会非常感激。

I have the following classes and tables, I want to find out how to map it in Fluent Nhibernate:

class File
        {
            public virtual int Id { get; set; }
            public virtual IList<FileParameter> FileParameters { get; set; }
            public virtual IList<File> DetailFile { get; set; }
        }

        class FileParameter
        {
            public virtual int Id { get; set; }
            public virtual File MasterFile { get; set; }
            public virtual string Name { get; set; }
            public virtual string DisplayName { get; set; }

            public virtual FileParameterValue FileParameterValue { get; set; }

        }

        class FileParameterValue
        {
            public virtual int Id { get; set; }
            public virtual File ParentFile { get; set;}
            public virtual FileParameter FileParameter { get; set; }
            public virtual string DefaultValue { get; set; }
            public virtual bool DisplayStatus { get; set; }
        }

Databse table

Table File
FileId, 

Table FileParameter
ParameterId, FileId, Name, DisplayName

Table FileParameterValue
FileParameterValueId, ParameterId, FileId, DefaultValue, DisplayStatus

What I want to achieve is that, there is one master file and its many details files. Each master file has its own FileParameter, and FileParameValue. Each of the master file's child files use the master file's FileParameter, but has its own FileParameterValue.

Any ideal would be very much appreicated.

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

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

发布评论

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

评论(1

黯淡〆 2024-12-06 05:25:30
class File
{
    public virtual int Id { get; set; }

    public virtual IDictionary<FileParameter, FileParameterValue> Parameters { get; set; }
    public virtual ICollection<File> Details { get; set; }
}

class FileParameter
{
    public virtual int Id { get; set; }
    public virtual File MasterFile { get; set; }
    public virtual string Name { get; set; }
    public virtual string DisplayName { get; set; }
}

class FileParameterValue
{
    public virtual int Id { get; set; }
    public virtual File ParentFile { get; set; }
    public virtual FileParameter FileParameter { get; set; }
    public virtual string DefaultValue { get; set; }
    public virtual bool DisplayStatus { get; set; }
}

class FileMap : ClassMap<File>
{
    public FileMap()
    {
        Id(file => file.Id).GeneratedBy.Identity();

        HasMany(file => file.Parameters)
            .AsEntityMap("ParameterId");

        // additional Properties
    }
}

class FileParameterMap : ClassMap<FileParameter>
{
    public FileParameterMap()
    {
        Id(param => param.Id).GeneratedBy.Identity();

        References(param => param.MasterFile, "FileId");

        // additional Properties
    }
}

class FileParameterValueMap : ClassMap<FileParameterValue>
{
    public FileParameterValueMap()
    {
        Id(param => param.Id).GeneratedBy.Identity();

        References(param => param.FileParameter, "ParameterId");

        // additional Properties
    }
}

您必须以编程方式确保,如果您在详细信息文件中添加参数值,则使用主文件的参数对象,

另请参阅类似问题NHibernate 映射

class File
{
    public virtual int Id { get; set; }

    public virtual IDictionary<FileParameter, FileParameterValue> Parameters { get; set; }
    public virtual ICollection<File> Details { get; set; }
}

class FileParameter
{
    public virtual int Id { get; set; }
    public virtual File MasterFile { get; set; }
    public virtual string Name { get; set; }
    public virtual string DisplayName { get; set; }
}

class FileParameterValue
{
    public virtual int Id { get; set; }
    public virtual File ParentFile { get; set; }
    public virtual FileParameter FileParameter { get; set; }
    public virtual string DefaultValue { get; set; }
    public virtual bool DisplayStatus { get; set; }
}

class FileMap : ClassMap<File>
{
    public FileMap()
    {
        Id(file => file.Id).GeneratedBy.Identity();

        HasMany(file => file.Parameters)
            .AsEntityMap("ParameterId");

        // additional Properties
    }
}

class FileParameterMap : ClassMap<FileParameter>
{
    public FileParameterMap()
    {
        Id(param => param.Id).GeneratedBy.Identity();

        References(param => param.MasterFile, "FileId");

        // additional Properties
    }
}

class FileParameterValueMap : ClassMap<FileParameterValue>
{
    public FileParameterValueMap()
    {
        Id(param => param.Id).GeneratedBy.Identity();

        References(param => param.FileParameter, "ParameterId");

        // additional Properties
    }
}

you have to make sure programmatically, that if you add a parametervalue in a detailsfile you use a parameter-object of the master file

see also for a similar problem NHibernate mapping

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