Property or indexer cannot be assigned to -- it's read only on fetching

Posts   
 
    
wexa
User
Posts: 38
Joined: 27-Jul-2007
# Posted on: 13-Oct-2007 18:29:36   

I have been using Llbl with SQL Server 2000 and it has been working great. However in a new project that I generated, with adapter, .Net 2.0 I am trying to fetch an entity from the database using the primary key:

DataAccessAdapter adapter = new DataAccessAdapter(); EmpresaEntity entidad = new EmpresaEntity(); if (!IsNewRecord()) { entidad.Id = Convert.ToInt32(GetKeyValue()); adapter.FetchEntity(entidad); }

but this time I am getting error:

Property or indexer cannot be assigned to -- it's read only

and

Error 2 The best overload method match for 'Isali.EntityClasses.EmpresaEntity.EmpresaEntity(SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2)' has some invalid arguments D:\Development\isali\web\catalogos\empresaEdit.aspx.cs 52 33 D:...\web\

I have checked the generator and all the stuff and is as I always and before it worked for other projects, but dont know this time what it may be.

Thankk you for your help

Posts: 254
Joined: 16-Nov-2006
# Posted on: 13-Oct-2007 21:29:28   

Can you please post the type of exception thrown including any inner exceptions and also a full stack trace for each exception and inner exception.

Note if you use something like the enterprise library 3.0 for logging purposes you will get a helpful log of the exception which you can attach to this thread.

wexa
User
Posts: 38
Joined: 27-Jul-2007
# Posted on: 13-Oct-2007 21:49:59   

I am getting the error on build time, so I can not see the stack trace. The application is working OK for adding new entities, fetching collections, it is an ASP app.

But my problem is for record edition since I can not load it. I have loaded this way befor but I am not sure why I am getting the error.

I am attaching one of the entities that is throwing the error. I am using the 2.5 version of llblgen.

Here is where I get the error:


public void SaveData()
    {
        SiniestroEntity entidad = new SiniestroEntity();
        DataAccessAdapter adapter = new DataAccessAdapter();

        // If it is edition we load it from DB
        if (!IsNewRecord())
        {
            entidad.Id = Convert.ToInt32(GetKeyValue());
            adapter.FetchEntity(entidad);
        }

...
....

}

private bool IsNewRecord()
    {
        string isNew = Request.QueryString["IsNew"];
        return (isNew != null && isNew != "");
    }

If i do this:


SiniestroEntity entidad = new SiniestroEntity(id);

I get an overload methos for the EnitityClassConstuctor

Posts: 254
Joined: 16-Nov-2006
# Posted on: 13-Oct-2007 22:30:36   

Reviewing the generated code

        /// Table field behavior characteristics (is nullable, is PK, is identity): false, false, true</remarks>
        public virtual System.Int32 Id
        {
            get { return (System.Int32)GetValue((int)SiniestroFieldIndex.Id, true); }

        }

I think the issue is you've defined the field as an identity field hence LLBLGEN would not allow you to set it and hence omit a set accessor. However it's not defined as primary key which is unusual.

If you intend not to make the Id field a primary key, perhaps because other fields are better candidates, then I would suggest you add a unique constraint to it, and LLBLGEN will generate an overloaded constructor which will accept an integer identifer.