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

I am working on a huge old project with a lot of fragile code, some of which have been since .NET 1.0, and other people have been and will work with it ... so I "Like to change as little as possible.

My solution has one project containing DataSet.xsd. This project is compiled into a separate assembly (Data.dll). A database schema includes several tables arranged more or less hierarchically, but the only way tables are actually related to each other is by joining. I can get for example. DepartmentRowand EmployeeRowobjects from auto-generated code. EmployeeRowcontains information from the employee matching DepartmentRowthrough the connection.

I am making a new report to view several departments and all their employees. If I use the existing data access scheme, all I can get is a result that looks like a table where each employee is presented on one line, and the department information is repeated again and again in the corresponding columns. For instance:.

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

But what the client would like is to have each department as a heading, with a list of employees under each. For instance:.

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

I am trying to do this by inheriting hierarchical objects from objects with auto-generated Row. For instance:.

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

Thus, I could attach data to the report using the collection of Department objects as a data source, each of which will place its list of employees in a subordinate report.

The problem is that it gives me an error The type Data.DataSet.DepartmentRow has no constructors defined. And when I try to create a constructor, for example

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

'Data.DataSet.DepartmentRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level. .

, ? - , ?

+3
3

, :

  • Data; , .
  • , , .

(DataSet.cs, VS2008 DataSet.xsd), , , :

public partial class DataSet {
    public partial class DepartmentRow {
        public DepartmentRow(global::System.Data.DataRowBuilder rb, string discard) : this(rb) { }
    }
    public partial class EmployeeRow {
        public EmployeeRow(global::System.Data.DataRowBuilder rb, string discard) : this(rb) { }
    }
}

:

public class Department : DataSet.DepartmentRow {
    public Department(global::System.Data.DataRowBuilder DataRowBuilder rb) : base(rb, "discard") { }

    public List<Employee> Employees;

    public string[] SomeFrequentlyUsedGroupOfFields {
        get {
            return new string[] { this.OneField, this.AnotherField };
        }
    }

    public bool CanUserSeeDepartmentInformation(int UserID) { }
}

!

, , , DataSetTableAdapters.DepartmentTableAdapter - DataSet.DepartmentRow, , Department /. , .

, , . (, - -.)

+1

. , , . "".

using System;
using System.Data;

namespace Blah
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class Class1 : MyDataSet.MyTableRow
    {
        public Class1(DataRowBuilder rb) : base(rb)
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}
+4

Source: https://habr.com/ru/post/1744990/


All Articles