This is a migrated thread and some comments may be shown as answers.
How to memorize option [serializable] in object class
5 Answers 50 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marchand
Top achievements
Rank 1
Marchand asked on 04 Feb 2011, 02:36 PM
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.

5 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 07 Feb 2011, 05:39 PM
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.
0
Marchand
Top achievements
Rank 1
answered on 07 Feb 2011, 05:54 PM
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,
0
PetarP
Telerik team
answered on 08 Feb 2011, 05:57 PM
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.
0
KubuliJohn
Top achievements
Rank 1
answered on 30 Jul 2012, 03:45 PM
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...
0
Alexander
Telerik team
answered on 02 Aug 2012, 01:31 PM
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.
Tags
General Discussions
Asked by
Marchand
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Marchand
Top achievements
Rank 1
KubuliJohn
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or