使用Fluent NHibernate时,vb.net开发人员可以使用哪些选项?

时间:2010-07-09 13:12:11

标签: vb.net fluent-nhibernate

过去一年我一直在使用c#,我很享受Fluent NHibernate的强大功能。我从朋友那里得到的一个问题是“很好,但vb.net程序员怎么能使用它?”

例如,下面是一个c#映射类。怎么会有人用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");
}
}

我的错 - 以上确实翻译了

尝试为配置创建流畅的界面怎么样?

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();
}

1 个答案:

答案 0 :(得分:6)

如果您的朋友那么懒惰,您可以使用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