subsonic / SubSonic-3.0-Templates

T4 Template Project for the peeps
http://subsonic.github.io/
105 stars 46 forks source link

Composite foreign keys #36

Open cdmdotnet opened 14 years ago

cdmdotnet commented 14 years ago

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, which can also leed to string == int type comparisomes. 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;
        }
    }