inheritance and identity

Thread is closed for posting
3 posts, 1 answers
  1. mromani
    mromani avatar
    7 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2010 Link to this post

    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. Answer
    IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 09 Jul 2010 Link to this post

    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
  3. mromani
    mromani avatar
    7 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2010 Link to this post

    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
Back to Top