Can I create a custom class that inherits from a strongly typed DataRow?

Posted by Calvin Fisher on Stack Overflow See other posts from Stack Overflow or by Calvin Fisher
Published on 2010-05-11T18:57:14Z Indexed on 2010/05/11 20:14 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

I'm working on a huge, old project with a lot of brittle code, some of which has been around since the .NET 1.0 era, and it has been and will be worked on by other people... so I'd like to change as little as possible.

I have one project in my solution that contains DataSet.xsd. This project compiles to a separate assembly (Data.dll). The database schema includes several tables arranged more or less hierarchically, but the only way the tables are actually linked together is through joins. I can get, e.g. DepartmentRow and EmployeeRow objects from the autogenerated code. EmployeeRow contains information from the employee's corresponding DepartmentRow through a join.

I'm making a new report to view multiple departments and all their employees. If I use the existing data access scheme, all I will be able to get is a spreadsheet-like output where each employee is represented on one line, with department information repeated over and over in its appropriate columns. E.g.:

Department1...Employee1...
Department1...Employee2...
Department2...Employee3...

But what the customer would like is to have each department render like a heading, with a list of employees beneath each. E.g.:

- Department1...
      Employee1...
      Employee2...
+ Department2...

I'm trying to do this by inheriting hierarchical objects from the autogenerated Row objects. E.g.:

public class Department : DataSet.DepartmentRow {
    public List<Employee> Employees;
}

That way I could nest the data in the report by using a collection of Department objects as the DataSource, each of which will put its list of Employees in a subreport.

The problem is that this gives me a The type Data.DataSet.DepartmentRow has no constructors defined error. And when I try to make a constructor, e.g.

public class Department : DataSet.DepartmentRow {
    private Department() { }
    public List<Employee> Employees;
}

I get a 'Data.DataSet.DepartmentRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level. error in addition to the first one.

Is there a way to accomplish what I'm trying to do? Or is there something else I should be trying entirely?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET