This is a migrated thread and some comments may be shown as answers.

inheritance and identity

2 Answers 101 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mromani
Top achievements
Rank 1
mromani asked on 09 Jul 2010, 10:41 AM

I have  2 classes, Persona and Alumno like this

namespace FormaModel 
    [Persistent(IdentityField = "id", VersionField = "version")] 
    public abstract class Persona 
    
        protected int id; 
    
        [FieldAlias("id")] 
        public int Id 
        
            get { return id; } 
            set { id = value; } 
        
    
        private string nombre; 
    
        public string Nombre 
        
            get { return nombre; } 
            set { nombre = value; } 
        
          
        protected short version; 
    
        [FieldAlias("version")] 
        public short VERSION 
        
            get { return version; } 
            set { version = value; } 
        
    
  
namespace FormaModel 
    [Telerik.OpenAccess.Persistent()] 
    public class Alumno : Persona 
    
    
        private int clase; 
    
        public int Clase 
        
            get { return clase; } 
            set { clase = value; } 
        
            
    

I use a RadGrid to show all objects from class Alumno I can also add a new one but, when I try to update i always get the following error

Changes are not possible if the primary key fields are not visible.
Please specify the id and version fields in the persistent attribute.
[Telerik.OpenAccess.Persistent(IdentityFied="id", VersionField="version"]

[UnsupportedException: Changes are not possible if the primary key fields are not visible.
Please specify the id and version fields in the persistent attribute.
[Telerik.OpenAccess.Persistent(IdentityFied="id", VersionField="version"]]
   Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.CreateObjectId(IDictionary keys, String& oldVersion) +99
   Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +215
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
   Telerik.Web.UI.GridTableView.PerformUpdate(GridEditableItem editedItem, Boolean suppressRebind) +353
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +1996


In OpenAccess guide it says you just need to specify identity and version in the base class, not in subclasses so I don't know.
Id and version fileds are protected in the base class so visible from the subclass.

I have used OpneAccess 2009.02 version (purchased) and I have now installed trial 2010.1 and I still have the same problem.

Any ideas about what I'm doing wrong?

Thanks
Miguel

2 Answers, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 09 Jul 2010, 01:26 PM
Hi Miguel,

You should declare the Persistent attribute (with version og id arguments) on the "table generating class" - that is -  the Alumno class in your case. On the abstract you just declare the Persistent attribute.

I have written a blog post about this. Check it out.

Regards

Henrik
0
mromani
Top achievements
Rank 1
answered on 24 Jul 2010, 03:25 PM
Hi Enrik,

My apologies for not answering you earlier I have been involved in other projects.

Your comment  made me understooth a lot of things.

I'm now implmenting your BaseEntity strategy.

Thanks

Miguel
Tags
General Discussions
Asked by
mromani
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
mromani
Top achievements
Rank 1
Share this question
or