How to memorize option [serializable] in object class

6 posts, 0 answers
  1. Marchand
    Marchand avatar
    15 posts
    Member since:
    Sep 2008

    Posted 04 Feb 2011 Link to this post

    Hi,

    I create my schema object, and I create my database (OK).

    First, I add in each object class the "option" ==> [Serializable].
    Secand, when I modify my entity schéma.....This "option" is loose for all object class....
    and I am obliged to re-apply option [Serializable] on each object class....

    Please, do you have a solution to apply option [Serializable] and that the system memorize it !!!

    In advance,
    Thanks,
    Richard.

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 07 Feb 2011 Link to this post

    Hello Marchand,

     This is actually the expected behavior. Since we use T4 templates to generate our classes, you are getting your model completely regenerated on each model change. In order to persist changes on a class level you will have to extend your generated classes with ones that are manually created by you. So for example if you have a class generated by us that is similar to this:

    public partial class Category
        {
            private int iD;
            public virtual int ID
            {
                get
                {
                    return this.iD;
                }
                set
                {
                    this.iD = value;
                }
            }
        }
    You will notice that the class we have generated is partial. This means that it can be extended by adding the a class with the same name and same modifiers in a different file like this:
    [Serializable]
        public partial class MetaClass1
        {
        }
    This way you will always keep the changes on a class level since they are in a different file than the one we regenerate.


    All the best,
    Petar
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  3. DevCraft banner
  4. Marchand
    Marchand avatar
    15 posts
    Member since:
    Sep 2008

    Posted 07 Feb 2011 Link to this post

    Hi,

    I don't understand your answer...

    ==> you said...
    public partial class Category
    {
                ......
    }
    This is the classe generated by telerik ORM.

    Them, I must created class, but the name a the partial class is "MetaClass1" ???
    [Serializable]
    public partial class MetaClass1
        {
        }


    Thanks,
  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 08 Feb 2011 Link to this post

    Hi Marchand,

     You are correct. I have copied the wrong class from my project. The actual partial class should look like this:

    [Serializable]
        public partial class Category
        {
        }
    The name of the partial class should match the one we have generated.


    Best wishes,
    Petar
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  6. KubuliJohn
    KubuliJohn avatar
    10 posts
    Member since:
    May 2004

    Posted 30 Jul 2012 Link to this post

    Is this answer still true?  I have dozens, soon to be hundreds of automatically generated entity classes - do I really have to create dozens soon to be hundreds of empty partial classes simply to apply the [Serializable] attribute?  They all have to be serializable in order to use them as the datasource for a RadGrid.

    [Update] - last statement is not true - I had just refactored all of my joining column names and had some datakeyname entries that were now being interpreted as the navigational entities instead of the foreign key field name.  However, an easier way to define persistent serialization settings would still be nice...
  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 02 Aug 2012 Link to this post

    Hello,

    If the Serializable attribute should be applied to all classes in the model, it might be easier to modify the code generation templates, so that the attribute is generated automatically.
    Here is how to modify the templates:
    - Open the (OpenAccess install path)\dsl(VS version)\CodeGenerationTemplates\CSharp(or VisualBasic)\Includes\MainCs.ttinclude file in a text editor
    - Edit the foreach loop on line 23 and add the following three lines:
    foreach(Telerik.OpenAccess.CodeGeneration.CodeClass @class in @namespace.Classes)
    {
        var serializableAttr = @class.CreateAttribute();
        serializableAttr.Name = "Serializable";
        @class.AddAttribute(serializableAttr);
        this.GeneratePerEntityFileBlock(@class as Telerik.OpenAccess.CodeGeneration.CodeElement, @namespace, defaultExtension);
    }
    - Save the template and from Visual Studio save the rlinq file in order to trigger the code generation.

    This way the Serializable attribute is added to each class before it is generated. Hope that helps.

    Greetings,
    Alexander
    the Telerik team
    OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
Back to Top
DevCraft banner