Linq to SQL获取子元素

时间:2015-02-13 06:34:09

标签: c# linq linq-to-sql

我的数据库中有四个表。现在,我想构建一个在客户端使用的对象。一切都适用于特殊语言,只有我的字段的翻译失败。

Parent Table:
ConfigTable

Child Table 1:
TestTranslations --> ConfigTableId Foreign Key
Child Table 2:
TestTableFields --> ConfigTableId Foreign Key

Child Table of Table 2:
TestTableFieldsTranslations --> TestTableFieldId Foreign Key

这是我的尝试......

var dbquery = from bdCon in this.GetAll()
            select new
            {
                bdCon,
                translations = from trans in bdCon.TestTranslations
                               where trans.LanguageID == languageId
                    select trans,
                fields = from fields in bdCon.TestTableFields where bdCon.Id == fields.ConfigTableId 
                         join fieldTrans in  this.Context.TestTableFieldsTranslations
                         on fields.Id equals fieldTrans.TestTableFieldId
             where fieldTrans.LanguageID == languageId
                         select fields
            };

        var query = dbquery
           .AsEnumerable() 
           .Select(m => m.bdCon);
        return query;

0 个答案:

没有答案