gpt4 book ai didi

vb.net - 这个 C# FluentNHibernate 组件映射的等效 VB.NET 代码是什么?

转载 作者:行者123 更新时间:2023-12-01 01:35:48 26 4
gpt4 key购买 nike

我是一名 C# 程序员,只能编写 VB.NET 代码。

在为我当前的客户进一步探索 NHibernate 时,我遇到了 FluentNHibernate,我觉得它非常有吸引力。

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

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

我从这里知道:
Component(Of Client)(Function(c) c.Address, ...)

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

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

例如,我得到的错误是我的 Address 类没有名为 Street 的属性成员。它看到我的地址类型,它识别它,但不知何故似乎有问题。我猜 VBNET 是为 lambda 表达式设计的很差,并且比 C# 进化得更少(抱歉,由于使用它的限制并且不能在 C# 中很容易地完成事情,所以有点沮丧。)

最佳答案

在 Visual Basic 2010 中,您可以编写以下内容

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)

编辑

这是一个 VS2008 风格的解决方案。我对 FluentNHibernate 并不是很熟悉,所以我不知道 M 的类型是什么,但是您应该能够用它的类型替换 MType 并且代码工作得很好。
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)

关于vb.net - 这个 C# FluentNHibernate 组件映射的等效 VB.NET 代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2201511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com