SubSonic 3 和复合外键

发布于 2024-08-08 23:17:54 字数 2748 浏览 2 评论 0原文

我目前正在评估 SubSonic 3 是否与旧数据库一起使用 - IE 几乎没有能力更改当前结构。

长话短说,SubSonic 2 很好地处理了我们的复合外键——但是我们正在寻找能够提供 linq 以及与 SS3 一起使用的所有其他功能的东西。

到目前为止,我发现 SS3 同时使用 ActiveRecord.tt 和 Classes.tt T4 模板,我的关系非常混乱。

我注意到,如果属性以“x”为后缀,则外键内的逻辑不包含“x” - 下面生成的代码示例。

    #region Properties

    partial void OnAUDIT_TYPEXChanging(int value);
    partial void OnAUDIT_TYPEXChanged();

    private int _AUDIT_TYPEX;
    public int AUDIT_TYPEX { 
        get{
            return _AUDIT_TYPEX;
        } 
        set{
            this.OnAUDIT_TYPEXChanging(value);
            this.SendPropertyChanging();
            this._AUDIT_TYPEX = value;
            this.SendPropertyChanged("AUDIT_TYPEX");
            this.OnAUDIT_TYPEXChanged();
        }
    }
    #region Foreign Keys
    public IQueryable<COMPANY_AUDIT_TYPE> COMPANY_AUDIT_TYPES
    {
        get
        {
              var db=new DB();
              return from items in db.COMPANY_AUDIT_TYPES
                   where items.AUDIT_TYPE == _AUDIT_TYPE // ERROR HERE NO "X" SUFFIX, SHOULD BE _AUDIT_TYPEX
                   select items;
        }
    }

当生成器到达复合键时,它们也会完全消失。他们不是生成一个属性,而是生成四个属性并开始混合比较体。请参阅下面生成的代码,

    #region Foreign Keys
    public IQueryable<EMPLOYEE> EMPLOYEES
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.COMPANY_ID == _COMPANY_ID
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES1
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.EMPLOYEE_NUM == _COMPANY_ID
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES2
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.COMPANY_ID == _EMPLOYEE_NUM
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES3
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.EMPLOYEE_NUM == _EMPLOYEE_NUM
                   select items;
        }
    }

理想情况下它只会生成

    #region Foreign Keys
    public IQueryable<EMPLOYEE> EMPLOYEES
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
              where items.COMPANY_ID == _COMPANY_ID && EMPLOYEE_NUM == _EMPLOYEE_NUM
                   select items;
        }
    }

Does SS3properlysupportcompositeforeignkeys,我的结果让我担心它不会。

I'm current evaluating SubSonic 3 for use with a legacy DB - IE very little ability to change the current structure.

Long story short SubSonic 2 handled our composite foreign keys pretty well - however we're looking for something that will providew linq and all the rest that goes along with SS3.

So far I've found that SS3 using both the ActiveRecord.tt and Classes.tt T4 templates I get very very messed up relationships.

I've noticed that if a property is suffixed with an "x" the logic inside the foreign keys doesn't include the "x" - example generated code below.

    #region Properties

    partial void OnAUDIT_TYPEXChanging(int value);
    partial void OnAUDIT_TYPEXChanged();

    private int _AUDIT_TYPEX;
    public int AUDIT_TYPEX { 
        get{
            return _AUDIT_TYPEX;
        } 
        set{
            this.OnAUDIT_TYPEXChanging(value);
            this.SendPropertyChanging();
            this._AUDIT_TYPEX = value;
            this.SendPropertyChanged("AUDIT_TYPEX");
            this.OnAUDIT_TYPEXChanged();
        }
    }
    #region Foreign Keys
    public IQueryable<COMPANY_AUDIT_TYPE> COMPANY_AUDIT_TYPES
    {
        get
        {
              var db=new DB();
              return from items in db.COMPANY_AUDIT_TYPES
                   where items.AUDIT_TYPE == _AUDIT_TYPE // ERROR HERE NO "X" SUFFIX, SHOULD BE _AUDIT_TYPEX
                   select items;
        }
    }

Also the generators completly die when they reach composite keys. Instead of generating ONE property they generate four and start mixing the comparsomes. see generated code below

    #region Foreign Keys
    public IQueryable<EMPLOYEE> EMPLOYEES
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.COMPANY_ID == _COMPANY_ID
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES1
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.EMPLOYEE_NUM == _COMPANY_ID
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES2
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.COMPANY_ID == _EMPLOYEE_NUM
                   select items;
        }
    }

    public IQueryable<EMPLOYEE> EMPLOYEES3
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
                   where items.EMPLOYEE_NUM == _EMPLOYEE_NUM
                   select items;
        }
    }

ideally it would just generate

    #region Foreign Keys
    public IQueryable<EMPLOYEE> EMPLOYEES
    {
        get
        {
              var db=new DB();
              return from items in db.EMPLOYEES
              where items.COMPANY_ID == _COMPANY_ID && EMPLOYEE_NUM == _EMPLOYEE_NUM
                   select items;
        }
    }

Does SS3 properly support composite foreign keys, my results lead me to fear that it does not.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文