Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve this exception "Could not find a setter for property 'ProductCode' in class ... "

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.

like image 774
André Luiz Avatar asked Apr 22 '15 18:04

André Luiz


1 Answers

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.

like image 151
Renatto Machado Avatar answered Sep 25 '22 05:09

Renatto Machado