从 Fluently 映射的列名称中检索属性名称
背景
我有一个名为“Dog”的类,它引用另一个名为“Tail”的类,该类具有一个名为“Size”的属性。所以,如果我想知道狗的尾巴大小,那就是“Dog.Tail.Size”。完美的。
我用 FluentNHibernate 映射了这个,如下所示:
public class DogMap : ClassMap<Dog>
{
public DogMap()
{
... other things here
Component(x => x.Tail, t => {
t.Map(x => x.Size, "DG_TL_SIZE").Length(2).Not.Nullable();
}
}
}
问题
列名为“DG_TL_SIZE”,我如何获得“Dog.Tail.Size”? 我知道我可以在获得 Dog.Tail.Size 后,获取 "persistentClass.GetRecursiveProperty("Dog.Tail.Size")"
来检索该属性并使用它。
问题是我需要更改它的值,因此我需要从中获取 PropertyInfo,但是当我有“Dog.Tail.Size”时,这应该不难获得。
那么,我怎样才能获得“Dog.Tail.Size”?
Background
I have a class called 'Dog', which references another class called 'Tail', which has a property called 'Size'. So, if i wanted to know the dog's tail size, it would be 'Dog.Tail.Size'. Perfect.
I have this mapped with FluentNHibernate Like this:
public class DogMap : ClassMap<Dog>
{
public DogMap()
{
... other things here
Component(x => x.Tail, t => {
t.Map(x => x.Size, "DG_TL_SIZE").Length(2).Not.Nullable();
}
}
}
The question
Having the column name "DG_TL_SIZE", how can i get "Dog.Tail.Size"?
I know i can, after i have Dog.Tail.Size, get the "persistentClass.GetRecursiveProperty("Dog.Tail.Size")"
to retrieve the property and work with it.
The thing is that i need to change its value, therefore i need a PropertyInfo from that, but that should not be hard to get when i have "Dog.Tail.Size".
So, how can i get the "Dog.Tail.Size"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以迭代所有属性,但所提供的代码需要重构
you can iterate through all properties, the code presented needs refactoring though