如何解决此异常“在类中找不到属性'ProductCode'的设置器..." [英] How to solve this exception "Could not find a setter for property 'ProductCode' in class ... "

查看:122
本文介绍了如何解决此异常“在类中找不到属性'ProductCode'的设置器..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下异常:

"Could not find a setter for property 'ProductCode'in class ...OrderItem.class "

属性(ProductCode)是我的表键之一.

The property (ProductCode) is one of my table keys.

查看类中的属性声明.

public class OrderItem : EntityBase
{
    public virtual short Company { get; set; }
    public virtual int Order { get; set; }
    public virtual string Seri { get; set; }
    public virtual string ProductCode { get; set; }
    public virtual string Crop { get; set; }
 .
 .
 .
 }

在我的地图下方

public MapOrderItem()
    {
        Table("IPED");
        CompositeId()
            .KeyProperty(c => c.Company, "C_EMP")
            .KeyProperty(c => c.Order, "P_PED")
            .KeyProperty(c => c.Seri, "S_PED")
            .KeyProperty(c => c.ProductCode, "C_PSV");
        Map(c => c.C_CFO).Not.Nullable();
        Map(c => c.AnotherCurrency).Column("V_IPE");
    .
    .
    .
    }

核实了与我类似的疑问,但是解决方案不能解决我的问题. 已经尝试使用

checked doubts similar to mine, but the solutions do not solve my problem. already tried to perform the mapping using

(c => c.ProductCode).Access.ReadOnly();
(c => c.ProductCode).Access.Field();
(c => c.ProductCode).ReadOnly();

直接在数据库中运行查询,不会显示任何错误,只会显示正确的数据.

to run the query directly in the database, does not show me any error, only the correct data.

推荐答案

解决方案

如果要使用NHibernate执行SQL,请验证SQL中列的别名.名称应与您的类中的属性完全相同.

Solution

If you are executing the SQL with NHibernate, verify the Alias Name of the column in your sql. The name should be exactly as name the property in your class.

例如错误:

select Product_Id as "ProductCode " 
from Products

请参见别名中的空格.这可能是导致您出错的原因.

See the white space in alias name. This can be cause of your error.

检查SQL中所有列的别名.

这篇关于如何解决此异常“在类中找不到属性'ProductCode'的设置器..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆