遗留数据库:多对一/引用,没有所有需要的关键列
我有一个引用(模板)文本的类,该文本对于每个租户和每个用例都有几个可能的文本
class Class1
{
[...]
public virtual Text TitleName { get; set; }
}
class Text
{
public virtual int TenantId { get; set; }
public virtual string Key { get; set; }
public virtual int Number { get; set; }
public virtual string Value { get; set; }
}
不幸的是,表结构看起来像
Table Class1
...
textnumber int,
Table Text
tenant int,
key varchar (10),
number int,
pkey(tenant, key, number);
因为 Class1 始终引用租户= 0(所有租户)并且键=“class1text”
编辑: 我需要 .Where() 但 References() 只有 HasMany()
到目前为止我有什么:
public void TextMap : ClassMap<Text>
{
public TextMap()
{
Table("restexts");
CompositeId()
.KeyProperty(t => t.TenantId, "tenant")
.KeyProperty(t => t.Key, "name")
.KeyProperty(t => t.Number, "number");
Map(t => t.Value, "content");
}
}
public void Class1Map : ClassMap<Class1>
{
public TextMap()
{
// mapping rest
References(c => c.TitleName)
.Columns("textnumber", ??, ??); // column 2 and 3 missing, because always the same
}
}
有什么想法吗?
I have a class referencing a (template)text which has for each tenant and each use case several possible texts
class Class1
{
[...]
public virtual Text TitleName { get; set; }
}
class Text
{
public virtual int TenantId { get; set; }
public virtual string Key { get; set; }
public virtual int Number { get; set; }
public virtual string Value { get; set; }
}
Unfortunatly the tablestructure looks like
Table Class1
...
textnumber int,
Table Text
tenant int,
key varchar (10),
number int,
pkey(tenant, key, number);
because Class1 always refers to tenant = 0 (all tenants) and key = "class1text"
Edit:
i need .Where() but References() doenst have it only HasMany()
What i have so far:
public void TextMap : ClassMap<Text>
{
public TextMap()
{
Table("restexts");
CompositeId()
.KeyProperty(t => t.TenantId, "tenant")
.KeyProperty(t => t.Key, "name")
.KeyProperty(t => t.Number, "number");
Map(t => t.Value, "content");
}
}
public void Class1Map : ClassMap<Class1>
{
public TextMap()
{
// mapping rest
References(c => c.TitleName)
.Columns("textnumber", ??, ??); // column 2 and 3 missing, because always the same
}
}
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 FluentNHibernate 以这种方式映射您的类,这是一种仅映射 OneToMany 关系中的一个字段的解决方法。
然后您可以在查询中添加其他字段的过滤器(tenent = 0 和 key =“class1text”)
我希望它有帮助
you can map your classes in this way with FluentNHibernate, it's a workaround to map only one field in OneToMany relationship.
Then you can add in your query the filters on the other fields (tenent = 0 and key = "class1text")
I hope it's helpful
时间不够了,我像
Map(c => c.TitleNameId, "textnumber");
一样映射它,并且每次需要标题名称时都必须记住租户和键名称(这是使用魔法值) :(running out of time i mapped it like
Map(c => c.TitleNameId, "textnumber");
and have to remember the tenant and key name everytime i need the titlename (which is using magic values :(