如何使用Fluent Nhibernate查询数据库

问题描述

我是nHibenate的新手,正在处理问题,以下是我的课程:

 public class CustomerEntity
{
    public virtual int CustomerId
    {
        get;
        set;
    }
    public virtual string Name
    {
        get;
        set;
    }
    public virtual string Fname
    {
        get;
        set;
    }
    public virtual string Phone
    {
        get;
        set;
    }

}

}

和我不知道其映射类是否正确的映射类:

public class CustomerMap : ClassMap<CustomerEntity> {

    public CustomerMap()
    {
        Map(x => x.CustomerId);
        Map(x => x.Name);
        Map(x => x.Fname);
        Map(x => x.Phone);
        
    }     
}

我有一个记录,我想简单地将其返回,我的控制器:

  public IActionResult Get()
    {
        var books = _session.Customer();

        return Ok(books);
    }

这是我的服务

  public IEnumerable<CustomerEntity> Customer()
    {

        IList<CustomerEntity> cust =
         _session.Query<CustomerEntity>()
      
      .ToList();
        return cust;
    }

我的会话工厂:

  public static ISessionFactory BuildSessionFactory(string DefaultConnection,bool create = false,bool update = false)
    {


      return Fluently.Configure().Database
  (MsSqlConfiguration.MsSql2012.ConnectionString
  (System.Configuration.ConfigurationManager.
  ConnectionStrings[DefaultConnection]
  .ConnectionString).ShowSql())
}))
    .Mappings(m =>
                      m.FluentMappings
                          .AddFromAssemblyOf<CustomerEntity>())
            .ExposeConfiguration(cfg => new SchemaExport(cfg)
                                            .Create(false,false))
            .BuildSessionFactory();
        


    }

但是查询返回[]表示空,并且我没有任何错误,知道吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...