0

我将使用示例解释我的问题。

假设我有linq查询结果。

var result1=from c in client
    select new my_type
    {
        ...
            stockDesctiption=??

    };

我们会说Client已归档称为stockId。这与表中的stockId相同dammadgeStockHistory。这些表在任何外键约束下都没有连接。

如果我需要dammadgeStockHistory.stockDescrption为每个客户获取如何做到这一点。

4

1 回答 1

1

按此字段连接表(不需要外键约束):

var result1 = from c in client
              join dsh in dammadgeStockHistory 
                  on c.stockId equal dsh.stockId
              select new my_type
              {
                stockId = c.stockId,
                // ...                  
                stockDesctiption = dsh.stockDescrption
              };

更新如果你想做“左加入”:

var result1 = from c in client
              join dsh in dammadgeStockHistory 
                  on c.stockId equal dsh.stockId into g
              from cdsh in g.DefaultIfEmpty()
              select new my_type
              {
                stockId = c.stockId,
                // ...                  
                stockDesctiption = cdsh == null ? null : dsh.stockDescrption
              };
于 2013-10-31T12:42:39.963 回答