What will be the equivalent VB.NET code for this C # FluentNHibernate component mapping?

I am a C # programmer, limited to writing VB.NET code.

When learning NHibernate for my current client, I came across FluentNHibernate, which I find really attractive.

But now I'm wondering how to "translate" this C # code to map components to 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 missed is how to continue the brackets in VB.NET, since there are no keywords to start, etc.

EDIT 1: Following Mr. Jared Par's instructions, I realized that his solution might work. If we take the time to read his answer, we may notice that we both do not know that MType is in his decision. I could find out that MType:

 FluentNHibernate.Mapping.ComponentPart(Of TComponent) 

So TComponent, in my opinion, is an anonymous type, which I will use as a parameter. From this perspective, since I want to map the properties of my Address object, replacing the TComponent in my help method signature does not seem 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 does not have, for example, a Street property element. He sees my type of address, he recognizes it, but somehow he seems to be a buggy. I think that VBNET is poorly designed for lambda expressions and less developed than C # (Sorry, a little disappointment due to the limitations of working with it and the inability to do things is VERY easy to do in C #.)

+4
source share
3 answers

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 am not the terrible familiar mind of FluentNHibernate, so I do not know what type M is, but you should be able to replace MType with its type and work with the code very well.

 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) 
+3
source

You cannot do multi-line lambda expressions in VB.Net. VB.Net 2010 will fix this, I believe. Can you not just create a dll in C # and then call it from VB.Net?

+1
source

Volya, I share your disappointment with the implementation of VB.NET lambdas with the .NET 3.5 / VS 2008 compiler. Actually, it is not that the language is poorly designed for lambda, just the implementation was incomplete .NET 3.5. Lambda support includes a lot of tricksters that can't be completed on time for the 2008 release. I want to note that you can continue to configure your current version of the .NET Framework using VS 2010 and get the complete lambdas support provided by the VS 2008 compiler. This means that you can use multi-line lambdas and anonymous Sub (to complete the previous existing anonymous function) , allowing Action <T> to work correctly. You can also avoid using the underscore for muitiline code statements. This is very convenient when working with lambdas directly, without API or LINQ problems. Hopefully this helps you make a strong argument for your client to upgrade your compiler without introducing the risk of significant changes. Besides the significant lack of support for iterator blocks, the implementation of VB.NET in VS 2010 is pretty sweet, as is Visual Studio based on WPF itself! John wigger

0
source

Source: https://habr.com/ru/post/1300317/


All Articles