3
I have a property that must be read-only, I performed mapping via code and assigned the parameter to read-only, however, it presents me an exception stating that the property’s Setter was not located
Exception:"Could not find a setter for property 'IndexValue 'in class ... "
my Indexvalue attribute, which is where the exception occurs is as follows in the class.
public class MyClass: EntityBase
{
.
.
.
public virtual decimal CropCode{ get; set ; }
public virtual decimal UnityDiscount { get; set; }
public virtual decimal IndexValue { get; set; }
}
where I have also tried to remove the virtual and failed.
my mapping was done as follows:
public MapMyClass()
{
Table("MyTable");
CompositeId()
.KeyProperty(c => c.Code, "CODI_EMP")
.KeyProperty(c => c.OrCode, "PEDI_PED")
Map(c => c.CropCode).Column("CODI_CUL");
Map(c => c.UnityDiscount).Column("DSAC_IPE");
.
.
Map(c => c.IndexValue).ReadOnly();
}
I tried to perform the mapping by also changing to:
Map(c => c.IndexValue).Access.ReadOnly();
and also with
Map(c => c.IndexValue).Access.Field();
The error occurs when nhibernate tries to execute the query, I already executed the query directly in the database and everything happens normal.
The estate
IndexValue
in the tableMyTable
the flame columnIndexValue
?– Fernando Leal
Not because Indexvalue is passed as a parameter for the sql query, I don’t need it in the database. I tried to create the property and not map it but also not solved..
– André Luiz
If it’s not in the database and it’s just a control field for the application, then simply don’t map it, because it doesn’t make any sense to want to map to Nhibernate something that even in the database is, if you’re seeing this need, sure you’re doing something very wrong.
– Fernando Leal
It was not mapped, that’s why I tried to map it and set it as Readonly in order to avoid the exception where it says it did not locate your Setter.
– André Luiz
But you’re using this attribute(
IndexValue
) in any Nhibernate Query? For if it is not in the database you cannot query with it.– Fernando Leal