I know there is a "CustomBehavior" for a property but it seems to do nothing.
11 Answers, 1 is accepted
There is no way to customize the generated properties however there are a couple of things you can do in this situation. You can either try out our new Fluent Mapping API which is basically a way for you to map your classes through code, this would mean that you could develop your classes with all the custom logic you need directly into your properties.
Another solution would be to extent the generated classes in partial classes. However using this approach you will only be able to add new properties and not redefine the already defined ones.
There is a third way to achieve your goal however it will require a little more effort on your side. You can modify the T4 templates that we use for code generation and strip off the property generation. Doing so you will be able implement all of your properties in partial classes. You can have a look at this article for more information on customizing our T4 templates.
However you will have to be very careful to define the properties with the same names that would have otherwise been generated. This is required because your model knows about those names and uses that knowledge whenever interpreting LINQ queries. Meaning if the names do not match you will not be able to execute LINQ queries over those properties.
I hope this is helpful, do let us know if you need further help.
the Telerik team
Unfortunately at the moment it does not do anything, it is supposed to be left there so our code generation can just provide a stub for the property and leave you to define this custom behaviour in the partial class. However we do not have such capabilities at the moment.
I am sorry for any confusion that this has introduced for you.
the Telerik team
I am afraid that this is not yet supported. The best way to increase the priority of that item would be to go to our product feedback portal and suggest the feature there. The more votes the request takes the higher the priority of implementing it will be.Kind regards,
the Telerik team
I was wondering if the CustomBehavior property has been implemented yet? I would like to have a field in the OpenAccess ORM model be 'calculated' (read-only) on the client side. How can I implement this?
I tried the use of 'partial', but as you have said, it does not let me return values for existing fields.
There are no further improvements in Calculated fields.
I was wondering what do you mean by "...I tried the use of 'partial', but as you have said, it does not let me return values for existing fields...."?
We have advised several clients to add non-persistent properties in a partial class to perform some calculations based on data already available in the records itself.
Please check this simple example:
This trick will work as lock as both partial class "pieces" are in the same namespace and the same project.
One of the things to pay attention to is that you have to map your new property (Names in our example) as Transient to instruct Telerik Data Access runtime not to try to use in on database level.
If you have different scenario in mind or have questions about the sample do not hesitate to get back to us.
What I meant was when one uses a 'partial', one can not 'redefine' an existing field to return custom data. You have to make up a new field name, as your example shows.
I see now how to create client side custom fields, thanks for the example. Is there anyway to have these custom fields show up in the ORM model diagrams?
There is no way to show any extension fields/properties in Visual Designer at the moment. Our intention there was to show only information relevant to the object-relational mapping and "client side" properties have limited value in such context.
If you want visual representation of your classes and their associations you can utilize Visual Studio Class Diagrams. There you will find all class properties plus interfaces, base types and methods. Class Diagrams will also auto update when changes to the included types are saved so you may only want to lay out the types in the best way after you have created the diagram.
In the above post you said, "One of the things to pay attention to is that you have to map your new property (Names in our example) as Transient to instruct Telerik Data Access runtime not to try to use in on database level."
How do I set the property to Transient?
Depending on the way your data model is defined you have to use different mean to mark a property as non-persistent (or transient):
- RLINQ model: use explicit mapping and just define your non-persistent property in a partial class;
- Fluent model: use .AsTransient() fluent method;
- Attributes mapped model: apply [Transient] attribute;