这个C#FluentNHibernate组件映射的等效VB.NET代码是什么? [英] What would be the equivalent VB.NET code for this C# FluentNHibernate component mapping?

查看:156
本文介绍了这个C#FluentNHibernate组件映射的等效VB.NET代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在进一步探索NHibernate的当前客户端时,我遇到了FluentNHibernate,我觉得它很吸引人。

但是现在我想知道如何将这个用于组件映射的C#代码翻译成VB.NET代码:

组件(x => x.Address,m =>
{
m.Map(x => x.Number);
m.Map(x => x.Street);
m.Map(x => x.PostCode);
});

我从这里知道:

<$ p $ (c)地址,...)

我想念的是如何继续VB.NET中的括号,因为没有Begin End关键字等等。


按照JaredPar先生的指示,我觉得他的解决方案可能有效。如果我们花时间阅读他的答案,我们可能会注意到,我们都不知道他的解决方案中的MType是什么。我可能已经发现MType是:



  FluentNHibernate.Mapping.ComponentPart(Of TComponent )




因此,根据我的理解,TComponent是一个匿名类型我将参数使用。从这个角度来看,因为我希望映射我的Address对象的属性,所以在我的帮助方法签名中替换TComponent似乎不起作用。




  Private Sub MapAdresseHelper(Of Adresse)(ByVal a As FluentNHibernate.Mapping.ComponentPart(Of (函数(m)m.Number)
a.Map(函数(m)m.Street).Length(50)
a.Map(函数(m)m.Number) m)m.PostCode).Length(10)
End Sub

是我的Address类没有名为Street的属性成员,例如。它看到我的地址类型,它可以识别它,但它似乎有些bug。我猜VBNET对于lambda表达式设计的不是很好,而且不像C#那样进化(对不起,因为使用它而受到一定的限制,并且不能在C#中很容易地完成任务)。 $ b

解决方案

在Visual Basic 2010中,您可以编写以下代码:

 <$ c $ (x)x.Address,Sub(m)
m.Map(Function(x)x.Number)
m.Map(Function(x)x.Street)
m.Map(Function(x)x.PostCode)
End Sub)

编辑



这是一个VS2008风格的解决方案。我不是很熟的FluentNHibernate,所以我不知道M的类型是什么,但是你应该能够用它的类型替换MType,并且代码工作得很好。


$ b $ (函数(x)x.Number)
m.Map(函数(x))b pre $ Private Sub Helper(ByVal m As MType)
m.Map (函数(x)x.PostCode)
结束小组


组件(函数(x)x.Address ,AddressOf Helper)


I'm a C# programmer constrained to write VB.NET code.

While exploring NHibernate further for my current client, I encountered FluentNHibernate, which I find real attractive.

But now, I wonder how to "translate" this C# code for component mapping into VB.NET code:

Component(x => x.Address, m =>
{
    m.Map(x => x.Number);
    m.Map(x => x.Street);
    m.Map(x => x.PostCode);
});

I know from here:

Component(Of Client)(Function(c) c.Address, ...)

what I miss is how to continue with the brackets in VB.NET, since there's no Begin End keywords or so.

EDIT 1: Following Mr. JaredPar instructions, I figured that his solution might work. If we take the time to read his answer, we may notice that we both don't know what the MType is within his solution. I might have found out that the MType is:

FluentNHibernate.Mapping.ComponentPart(Of TComponent)

Thus, TComponent is, from my understanding, an anonymous type that I shall parameter to use. From this point of view, since I wish to map the properties of my Address object, replacing TComponent in my help method signature seems not to work.

Private Sub MapAdresseHelper(Of Adresse)(ByVal a As FluentNHibernate.Mapping.ComponentPart(Of Adresse))
    a.Map(Function(m) m.Number)
    a.Map(Function(m) m.Street).Length(50)
    a.Map(Function(m) m.PostCode).Length(10)
End Sub

The error I get is that my Address class doesn't have a property member named Street, for instance. It sees my Address type, it recognizes it, but it seems buggy somehow. I guess VBNET is poorly designed for lambda expressions and is less evolved than C# (Sorry, a bit of frustration due to the constraint of working with it and not being capable of doing things VERY easily done in C#.)

解决方案

In Visual Basic 2010 you can write the following

Component(Function(x) x.Address, Sub(m)
  m.Map(Function(x) x.Number)
  m.Map(Function(x) x.Street)
  m.Map(Function(x) x.PostCode)
  End Sub)

EDIT

Here is a VS2008 style solution. I'm not terrible familiar wit FluentNHibernate so I don't know what the type of M is but you should be able to replace MType with it's type and have the code work just fine.

Private Sub Helper(ByVal m As MType)
  m.Map(Function(x) x.Number)
  m.Map(Function(x) x.Street)
  m.Map(Function(x) x.PostCode)
End Sub

...  
Component(Function(x) x.Address, AddressOf Helper)

这篇关于这个C#FluentNHibernate组件映射的等效VB.NET代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆