QueryOver错误无法执行查询 - 输入字符串格式不正确

时间:2016-02-02 11:06:51

标签: c# sql-server nhibernate queryover

我尝试在SQL Server表上执行下面的QueryOver语句,并且我收到了一个异常:

  

“无法执行查询 - 输入字符串格式不正确”

QueryOver语句:

IQueryOver<Customer> queryOver = this.session.QueryOver<Customer>();
IList<Customer> customerList = queryOver.List<Customer>();

表格:

CREATE TABLE dbo.CUSTOMER (
    CUST_CODE varchar(15) NOT NULL,
    CUST_NAME varchar(50) NULL
) 

班级:

public class Customer
{
    public virtual long CustomerId { get; set; }
    [ColumnName("CUST_NAME")]
    public virtual string CustomerName{ get; set; }
}

映射:

public class CustomerMap : ClassMap<Customer>
{
    public CustomerMap()
    {
        Schema("DBO");
        Table("CUSTOMER");
        Id(c => c.CustomerId).GeneratedBy.Assigned().Column("CUST_CODE");
        Map(c => c.CustomerName).Nullable().Column("CUST_NAME");
    }
}

有人能告诉我这个问题出了什么问题吗?

1 个答案:

答案 0 :(得分:1)

嗯,有C#属性long

public virtual long CustomerId { get; set; }

long 映射到列"CUST_CODE"

// type is deferred from type == long
Id(c => c.CustomerId).GeneratedBy.Assigned().Column("CUST_CODE");

'CUST_CODE' string

CREATE TABLE dbo.CUSTOMER (
    CUST_CODE varchar(15) NOT NULL,
    ...

这就是问题所在。改变其中一个以相互匹配......