How to solve this exception “Could not find a setter for property 'ProductCode' in class … ”

六眼飞鱼酱① 提交于 2019-12-06 22:44:47

问题


I am getting the following exception:

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

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

see how is the property declaration in the class.

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; }
 .
 .
 .
 }

below this my mapping.

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.


回答1:


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.


e.g. incorrect:

select Product_Id as "ProductCode " 
from Products

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

Check the alias name for all columns in your sql.



来源:https://stackoverflow.com/questions/29805820/how-to-solve-this-exception-could-not-find-a-setter-for-property-productcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!