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

[Solved] adding code to the set property method when using entity diagrams

1 Answer 112 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.
Myth
Top achievements
Rank 1
Myth asked on 31 Aug 2010, 12:33 PM
When using the object scope provider, the only part of a class that was generated by the wizard were the variables. This allowed you write/customize a property's "set" method. For example to make sure an integer value isn't below 0 or to implement the Inotifypropertychanged event. However, how would one do this when using the new Entity diagram style? As now both the variables and the properties are auto generated.

Best regards,
Stijn

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 02 Sep 2010, 03:56 PM
Hello Myth,

You can create a second partial class and add another property which contains your custom logic. For example, if you want to add some logic to the CategoryID property of the Product class, you can do the following:
public partial class Product
{
    public int? CategoryId
    {
        set
        {
            if (!value.HasValue || value > 0)
            {
                this.categoryID = value;
            }
        }
    }
}
The disadvantage is that you cannot use the same name as the one of the autogenerated property.

Maybe in this case it would be better to implement the INotifyPropertyChanging(ed) interfaces. You can see how this can be accomplished via code generation in this article. Hope that helps.

Kind regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Myth
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or