1

假设我有三个表类型,翻译和语言类型有一个列表

First
Second
Third

翻译将在 2 种语言中具有该类型列表的值

Value1  german
Value1  french
Value2  german
Value2  french

ETC...

目前,我正在使用一个存储过程,该过程接受从 Type 表中读取的语言,并在 Translation 表中存在翻译值时覆盖该值(如果不只是从 Type 表中返回值)......希望这是有道理的。

我现在使用的存储过程是这样的。

    CREATE PROCEDURE [dbo].[GetTypesLocalized]   
 -- Add the parameters for the stored procedure here   
 @languageId int 
AS  
BEGIN  
 -- SET NOCOUNT ON added to prevent extra result sets from  
 -- interfering with SELECT statements.  
 SET NOCOUNT ON;  

    -- Insert statements for procedure here  
 SELECT ISNULL(tr.Name, t.Name) AS Name,  
 FROM Type AS t  
  LEFT OUTER JOIN Translation AS tr ON  
   (tr.FK = t.Id AND tr.Type = 'type' AND tr.LanguageId = @languageId)  
END  

我将如何使用 linq 语法在 EF 中表示该查询?

4

1 回答 1

0
var query = from t in db.Type
            from tr in db.Translation
            where t.Id == tr.FK && tr.Type == "type" && tr.LanguageId == langId
            select tr.Name == null ? t.Name : tr.Name;
于 2013-01-31T20:42:22.480 回答