开发者

Rename a foreign row in a Strong Typed DataSet

开发者 https://www.devze.com 2023-03-06 10:47 出处:网络
Let\'s say I have the following DataBase/DataSet Schema structure : Table Employee EmployeeID PK Name Table Desk

Let's say I have the following DataBase/DataSet Schema structure :

Table Employee

  • EmployeeID PK
  • Name

Table Desk

  • DeskID PK
  • NumberOfLamps
  • OwnerEmployeeID FK to EmployeeID

Of course, I can access the Employee name doing this :

string employeeName = desk.EmployeeRow.Name;

I would like to access his name doing this instead :

string employeeName = desk.OwnerEmployee.Name;

In this example, it's basically pointless, I know, but let's say you have another table representing an n-to-n mapping for Boss/Employee :

Table WhosTheBoss

  • WhosTheBossID PK
  • BossEmployeeID FK
  • SlaveEmployeeID FK

Accessing their names wouldn't be fun, imho :

string notCool = string.Format(
    "{0} is a slave to {1}.",
    whosTheBoss.EmployeeRow1.Name,
    whosTheBoss.EmployeeRow.Name);

Edit: I was checking in the designer generated code and here is what I currently have:

[global::System.Di开发者_StackOverflowagnostics.DebuggerNonUserCodeAttribute()]
public EmployeeRow EmployeeRow {
    get {
        return ((EmployeeRow)(this.GetParentRow(this.Table.ParentRelations["FK_Desk_Employee"])));
    }
    set {
        this.SetParentRow(value, this.Table.ParentRelations["FK_Desk_Employee"]);
    }
}

And what I'd like to have would be :

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public EmployeeRow OwnerEmployeeRow {
    // ...
}

But I can't change that or the designer will probably go postal on me...


I was able to rename the class name generated for the dataset data-table by using the XML schema editor on the auto-generated .xsd file.

Maybe searching for EmployeeRow in this file and changing it - then rebuild helps you, too?


First off, I love your use or "notCool" and slavery.

You didn't mention which Object Relational Mapper you are using, but most will allow for you to change the names of the objects to which you have foreign keys. For example, in Entity Framework, you can edit the Properties on the Entity Data Model to provide friendlier names.

0

精彩评论

暂无评论...
验证码 换一张
取 消