重命名强类型数据集中的外部行

发布于 2024-11-07 04:55:42 字数 1359 浏览 8 评论 0原文

假设我有以下数据库/数据集架构结构:

Table Employee

  • EmployeeID PK
  • Name

Table Desk

  • DeskID PK
  • NumberOfLamps
  • OwnerEmployeeID FK to EmployeeID

当然,我可以这样做访问员工姓名:

string employeeName = desk.EmployeeRow.Name;

我想访问他的姓名这样做

string employeeName = desk.OwnerEmployee.Name;

:在这个例子中,我知道它基本上没有意义,但是假设您有另一个表代表 Boss/Employee 的 n 到 n 映射

: WhosTheBoss

  • WhosTheBossID PK
  • BossEmployeeID FK
  • SlaveEmployeeID FK

访问他们的名字并不有趣,恕我直言:

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



编辑:我正在检查设计师生成的代码,这是我目前拥有的:

[global::System.Diagnostics.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"]);
    }
}

我想要的是:

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

但我无法更改它,否则设计师可能会邮寄在我身上...

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.Diagnostics.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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

享受孤独 2024-11-14 04:55:42

我能够通过在自动生成的 .xsd 文件上使用 XML 模式编辑器来重命名为数据集数据表生成的类名。

也许在此文件中搜索 EmployeeRow 并更改它 - 然后重建也可以帮助您?

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?

芯好空 2024-11-14 04:55:42

首先,我喜欢你的使用或“不酷”和奴役。

您没有提到您正在使用哪个对象关系映射器,但大多数都允许您更改具有外键的对象的名称。例如,在实体框架中,您可以编辑实体数据模型上的属性以提供更友好的名称。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文