SQLMetal多个外键指向一个表格文档 [英] SQLMetal Multiple Foreign Keys Pointing to One Table Issue

查看:184
本文介绍了SQLMetal多个外键指向一个表格文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改 - 清理的问题,以更好地反映实际的问题:

Edit - Cleaning up question to better reflect the actual issue:

我用SQLMetal生成从我们的SQL Server DB数据库类。最近,我需要添加一个表,其中有多个外键指向同一个表。使用LINQPad玩弄新表,我能够为外键的访问属性,像这样:

I'm using SQLMetal to generate database classes from our SQL Server db. Recently, I needed to add a table that had multiple foreign keys pointing to the same table. Using LINQPad to play around with the new tables, I was able to access properties for both foreign keys like so:

  • record.FK_AId
  • record.FK_BId
  • record.FKA
  • record.FKB

......这是多么我希望它。现在的问题是,由SQLMetal生成的类产生这些特性:

...which is just how I would expect it. The problem is, the classes generated by SQLMetal produce these properties:

  • record.FK_AId
  • record.FK_BId
  • record.FKA
  • record.FKBTableNameGoesHere

现在我的可以的只是cange生成的类等等FKBTableNameGoesHere会FK_B,但生成的文件经常改变由不同的团队成员,因此这将是一个巨大的痛苦。是否有一个容易解决的呢?

Now I could just cange the generated classes so FKBTableNameGoesHere would be FK_B, but the generated files are changed very often by different team members, so that would be a huge pain. Is there an easy fix for this?

在此先感谢。

编辑2 所以,我认为解决办法是只创建了一个属性叫什么,我想这是一个分部类,并让的getter / setter点到指定的不良特性。这工作的选择,但不是在where子句和这样的使用它。任何人有一个解决方案?

Edit 2 So, I thought the solution would be to just create a partial class that had a property named what I wanted it to be, and let the getter/setter point to the poorly named property. That worked for selecting, but not using it in where clauses and such. ANYONE have a solution??

推荐答案

所以,我的解决办法是添加另一部分类,并添加用get /设置属性指着名字古怪的FKBTableNameGoesHere财产。这样,我们就不必保留修改所生成的类。不完全解决问题,但应该更清楚地向开发商什么属性的意思。任何人看到任何潜在的问题与解决办法?

So, my solution was to just add another partial class and add a property with the get/set pointed to the oddly named FKBTableNameGoesHere property. That way we don't have to keep modifying the generated classes. Not exactly solving the problem, but should make it clearer to developers what the property means. Anyone see any potential issues with that solution?

修改 - 那么,显然这仅适用于选择的数据,而不是过滤方法就可以了。不容易,因为我所希望的修复程序。任何人有任何其他建议?

Edit - So, apparently this only works for selecting data and not filtering based on it. Not as easy of a fix as I had hoped. Anyone have any other suggestions?

编辑2 - Jeeze,认为这将是一个有点常见的问题,但我想不会。无论如何,事实证明我是正确的轨道上与此有关。我发现这个职位:

Edit 2 - Jeeze, thought this would be somewhat of a common problem but I guess not. Anyway, turns out I was on the right track with this. I found this post:

[LINQ到SQL]多个外键同一表

这给了我,我不能只是直接链接到的getter / setter的另一个属性,因为有可能很多比回事幕后更多的想法。这家伙的解决方案是不完全的答案,但它给我发的分辩方向。添加关联属性是终于做到了:

Which gave me the idea that I couldn't just link directly to the getter/setter for another property since there's probably a lot more than that going on behind the scenes. This guys solution wasn't exactly the answer, but it sent me in the rigth direction. Adding the association attributes is what finally did it:

public partial class ProblemClass
{
    [Association(Name = "FK__SomeLinkHere", Storage = "_OriginalPoorlyNamedStorageVariable", ThisKey = "FK_1_Id", OtherKey = "Id", IsForeignKey = true)]
    public FKType MyNewBetterName
    {
        get
        {
            return this._OriginalPoorlyNamedStorageVariable.Entity;
        }

        set
        {
            this.OriginalPoorlyNamedStorageVariable = value;
        }
    }
}

要离开赏金开放的人谁还能拿出一个清晰的解决方案。

Going to leave the bounty open for anyone who can still come up with a cleaner solution.

这篇关于SQLMetal多个外键指向一个表格文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆