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

Posted by Will Marcouiller on Stack Overflow See other posts from Stack Overflow or by Will Marcouiller
Published on 2010-02-04T16:54:26Z Indexed on 2010/03/14 19:55 UTC
Read the original article Hit count: 397

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#.)

Thanks!

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about c#-to-vb.net