1

我们正在使用 SQL Server 并且应用程序是使用DBML开发的。现在由于急切加载的功能,我遇到了问题。我有一个表 A表 B有关系。(A -> B)。现在,当我尝试加载表 A 时,它将获取表 B 的所有字段。罪魁祸首是表 B 有 2-3 列,这些列非常重,包含byte array数据,并且由于这些列,获取数据需要太多负载表A也。

问题
当我获取表 A 时,我可以有这样的方式,我可以只加载表 B 的几列(不是所有列)吗?

我已经尝试过
我收到此错误:

指定的表达式必须采用 pA 的形式,其中 p 是参数,A 是属性或字段成员。

当我尝试使用以下代码时-

DataContext2.DeferredLoadingEnabled = false;
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<A>(x => x.Campaign);
options.LoadWith<A>(x => x.AnotherTable);
options.LoadWith<A>(x => x.B.Select(o => new B
{
    Id = o.Id,
    Name = o.Name,
    Person = o.Person,
}).ToList());
DataContext2.LoadOptions = options;
4

1 回答 1

1

只需使用join并且select仅使用必要的列:

var yourQuery = (from t_A in dbContext.Table_A
             join t_B in dbContext.Table_B on t_A.ID equals t_B.ID                 
             //use where operator to filter rows
             select new {
                 Id = t_B.Id,
                 Name = t_B.Name,
                Person = t_B.Person
                  // any field you want from your query
             }).ToList();
于 2019-01-21T15:08:43.477 回答