asp.net 5,mvc 6 api和nhibernate有一个例子吗?

时间:2022-08-29 16:38:09

The only examples that i found are with Entity Framework 7 that is compatible with asp.net 5.

我发现的唯一例子是与asp.net 5兼容的Entity Framework 7。

i'm not sure is this question should be posted here, but someone can point me where to know about nhibernate support for asp.net vNext.

我不确定这个问题应该发布在这里,但是有人可以指出我在哪里知道对于asp.net vNext的nhibernate支持。

thanks in advance

提前致谢

2 个解决方案

#1


1  

http://druss.co/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu/

http://druss.co/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu/

I had a few minutes, I've tested it, working fine with SQL2008R2.

我有几分钟,我已经测试过,与SQL2008R2一起工作正常。

public class Item
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

public class ItemMap : ClassMap<Item>
{
    public ItemMap()
    {
        Id(item => item.Id).GeneratedBy.Increment();
        Map(item => item.Name);
        Table("Item");
    }
}

public class ItemContext
{
    public IList<Item> GetAll()
    {
        var sessionFactory = CreateSessionFactory();

        using (var session = sessionFactory.OpenSession())
        {
            using (var trans = session.BeginTransaction())
            {
                var item = new Item
                {
                    Id = 2,
                    Name = "Test row"
                };
                session.SaveOrUpdate(item);
                trans.Commit();
            }

            using (session.BeginTransaction())
            {
                var items = session.CreateCriteria(typeof (Item)).List<Item>();
                return items;
            }
        }
    }

    private ISessionFactory CreateSessionFactory()
    {
        return Fluently
            .Configure()
            .Database(
                MsSqlConfiguration.MsSql2008
                    .ConnectionString(c =>
                        c.Database("NHibernateTest")
                            .Server(".\\DEV2008R2")
                            .TrustedConnection()
                    ))
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
            .BuildSessionFactory();
    }


}

#2


0  

NHibernate should not generally care which version of ASP.Net you use. Your use of NHibernate would be unaffected compared to earlier versions of ASP.Net.

NHibernate一般不应该关心你使用哪个版本的ASP.Net。与早期版本的ASP.Net相比,您对NHibernate的使用不会受到影响。

If you're aware of some particular reason it wouldn't work, please add a comment.

如果你知道某些特殊原因它不起作用,请添加评论。

#1


1  

http://druss.co/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu/

http://druss.co/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu/

I had a few minutes, I've tested it, working fine with SQL2008R2.

我有几分钟,我已经测试过,与SQL2008R2一起工作正常。

public class Item
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

public class ItemMap : ClassMap<Item>
{
    public ItemMap()
    {
        Id(item => item.Id).GeneratedBy.Increment();
        Map(item => item.Name);
        Table("Item");
    }
}

public class ItemContext
{
    public IList<Item> GetAll()
    {
        var sessionFactory = CreateSessionFactory();

        using (var session = sessionFactory.OpenSession())
        {
            using (var trans = session.BeginTransaction())
            {
                var item = new Item
                {
                    Id = 2,
                    Name = "Test row"
                };
                session.SaveOrUpdate(item);
                trans.Commit();
            }

            using (session.BeginTransaction())
            {
                var items = session.CreateCriteria(typeof (Item)).List<Item>();
                return items;
            }
        }
    }

    private ISessionFactory CreateSessionFactory()
    {
        return Fluently
            .Configure()
            .Database(
                MsSqlConfiguration.MsSql2008
                    .ConnectionString(c =>
                        c.Database("NHibernateTest")
                            .Server(".\\DEV2008R2")
                            .TrustedConnection()
                    ))
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
            .BuildSessionFactory();
    }


}

#2


0  

NHibernate should not generally care which version of ASP.Net you use. Your use of NHibernate would be unaffected compared to earlier versions of ASP.Net.

NHibernate一般不应该关心你使用哪个版本的ASP.Net。与早期版本的ASP.Net相比,您对NHibernate的使用不会受到影响。

If you're aware of some particular reason it wouldn't work, please add a comment.

如果你知道某些特殊原因它不起作用,请添加评论。