我正在开发一个 ASP.NET/C#/fluent nHibernate 项目,最近发现了Component
我想要实现的映射功能。我相信我的类定义和映射文件是正确的,但是我很难使用我的服务和/或存储库层检索组件信息以将其显示在 aDetailsView
或FormView
.
当我使用 anObjectDataSource
来检索信息时,在相应视图中生成的 aspx 代码将整个组件放在 a 中TextBox
:
<asp:TextBox ID="extraTextBox" runat="server" Text='<%# Bind("extra") %>' />
我在网上找到了大量关于如何进行映射本身的资源,但无法找到更多关于正确显示组件的指导。任何指导将不胜感激!
// Stripped down classes
public partial class ProjectExtra
{
private int _test1;
private int _test2;
public ProjectExtra() {}
public virtual int test1 { get { return this._test1; } set { this._test1 = value; } }
public virtual int test2 { get { return this._test2; } set { this._test2 = value; } }
}
public partial class Project
{
private int _pkProjectID;
private ProjectExtra _extra;
public Project() {}
public virtual ProjectExtra extra
{
get
{
return this._extra;
}
set
{
this._extra = value;
}
}
public virtual int pkProjectID
{
get
{
return this._pkProjectID;
}
set
{
this._pkProjectID = value;
}
}
}
// stripped down mapping
public class ProjectMap : ClassMap<Project>
{
public ProjectMap()
{
Table(@"Project");
LazyLoad();
Id(x => x.pkProjectID)
.Column("pkProjectID")
.Access.Property()
.Not.Nullable()
.GeneratedBy.Identity();
Component<ProjectExtra>(x => x.extra, m =>
{
// JobsCreatedActual and JobsCreatedEstimate are two integer columns
// in the Project database table
m.Map(x => x.test1).Column("JobsCreatedActual");
m.Map(x => x.test2).Column("JobsCreatedEstimate");
Not.LazyLoad();
});
}
}