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

How to handle inheritance with datasource

1 Answer 116 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Olivier
Top achievements
Rank 1
Olivier asked on 04 Jun 2019, 09:08 AM

Hi,

I would like to have a list of objects which all inherit of the same type but can have some specific properties.

Exemple:

public class MyPrimaryClass
{
    public int CommonProperty { get; set; }
 }
 
public class MyInheritedClass1 : MyPrimaryClass
{
    public int SpecificProperty1 { get; set; }
 }
 
public class MyInheritedClass2 : MyPrimaryClass
{
    public int SpecificProperty2 { get; set; }
 }

 

And I would like to display these specific properties and if possible display each object in a specific format. Do you have an idea of how I can do that using telerik reporting ? I can't find any example or thread on this topic, but maybe I just didn't use the right key words ;)

Thanks and regards,
Olivier

1 Answer, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 06 Jun 2019, 06:49 PM
Hi Olivier,

When using an Inheritance Hierarchy for your database the best approach is to use Business Objects (POCO's) with an ObjectDataSource component. A sample is available in the How-To Bind to Business Object documentation.

Additionally, the [DataObject] declaration in the sample will enable the ability to write specific methods and queries that can shape the data output in the ways you describe. 

For example, the below methods from the sample get a list of products in different ways. 

Sample Methods

// Gets products bellow a specified max price.
[DataObjectMethod(DataObjectMethodType.Select)]
public IList<Product> GetProducts(decimal maxPrice)
{
    return this.GetAllProducts().FindAll(product => product.ListPrice <= maxPrice);
}
 
// Gets products of specific model and a color.
[DataObjectMethod(DataObjectMethodType.Select)]
public IList<Product> GetProducts(int productModelID, string color)
{
    return this.GetAllProducts().FindAll(product => (product.ProductModelID == productModelID && product.Color == color));
}


Please let me know if you have any additional questions and thank you for choosing Telerik Reporting.

Regards,

Eric R
Progress Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Olivier
Top achievements
Rank 1
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
Share this question
or