How to map a read-only property in Fluent nhibernate, error when identifying Setter

Asked

Viewed 245 times

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 table MyTable the flame column IndexValue?

  • 1

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

  • 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.

  • 2

    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.

  • 2

    But you’re using this attribute(IndexValue) in any Nhibernate Query? For if it is not in the database you cannot query with it.

1 answer

2


Check your search may, be you have some table that is with incorrect value, all forms of mapping you tried to use are correct.

In Oracle it is necessary that you take care to put the reference name of the equal columns. It may be that a space will give you all this trouble. In the error you listed the name of your 'IndexValue' is with space at the end, if your column is not with that space, this may be the cause of the problem.

  • 1

    Really, the problem was the space, Removie and worked perfectly on the oracle base. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.