Tutorial :What options are available for a vb.net developer when using Fluent NHibernate?



Question:

I've been using c# for the past year and I enjoy the power you get with Fluent NHibernate. One question that I get from friends is "nice but how can vb.net programmers use this?"

So for example- the below is a c# mapping class. How would someone do this with vb.net?

public class PostMap : ClassMap<post>  {  public PostMap()  {  Table("Posts");  Id(x => x.ID);  Map(x => x.PublishDate, "PublishDate");  Map(x => x.Title, "Title");  Map(x => x.uri, "uri");  Map(x => x.Content, "Content");    HasMany(x => x.CommentCollection).KeyColumn("PostID");  HasManyToMany(x => x.TagCollection).Table("TagMap").ParentKeyColumn("PostID").ChildKeyColumn("TagID");  }  }  

My fault - the above does translate

What about trying to create the fluent interface for config though?

private static ISessionFactory CreateSessionFactory()  {  var cfg = Fluently.Configure()  .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("Blog")))  .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))  .ExposeConfiguration(x => x.SetProperty("current_session_context_class", "web"));    return cfg.BuildSessionFactory();  }  


Solution:1

If your friends are that lazy you might suggest them using an online converter:

Public Class PostMap Inherits ClassMap(Of post)      Public Sub New()          Table("Posts")          Id(Function(x) x.ID)          Map(Function(x) x.PublishDate, "PublishDate")          Map(Function(x) x.Title, "Title")          Map(Function(x) x.uri, "uri")          Map(Function(x) x.Content, "Content")            HasMany(Function(x) x.CommentCollection).KeyColumn("PostID")          HasManyToMany(Function(x) x.TagCollection).Table("TagMap").ParentKeyColumn("PostID").ChildKeyColumn("TagID")      End Sub  End Class    Private Shared Function CreateSessionFactory() As ISessionFactory      Dim cfg = Fluently.Configure() _          .Database(MsSqlConfiguration.MsSql2005.ConnectionString(Function(c) c.FromConnectionStringWithKey("Blog"))) _          .Mappings(Function(m) m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) _          .ExposeConfiguration(Function(x) x.SetProperty("current_session_context_class", "web"))        Return cfg.BuildSessionFactory()  End Function  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »