Fluent NHibernate Mapping issues
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, Dis开发者_高级运维playName
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.
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
精彩评论