2016-09-06 82 views
-4

如何將以下linq轉換爲sql轉換爲lambda表達式。謝謝。將Linq查詢轉換爲Lambda

var existing = (from a in db.sms_imported_trn_code 
       where !db.sms_description.Any(m => m.trn_code == a.trn_code) 
       select new { trn_code = a.trn_code }).ToList(); 

編輯:

我曾嘗試以下查詢,但它給我的錯誤。請查看下面的圖片。

View Error Image

我的模型類是低於

public class sms_imported_trn_code 
    { 
     public int id { get; set; } 
     public string trn_code { get; set; } 
     List<sms_imported_trn_code> sms_import_list { get; set; } 
    } 
} 


public class sms_description 
    { 

     public int id { get; set; } 
     public string trn_code { get; set; } 
     public string Description { get; set; } 

     [DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)] 
     public DateTime create_date { get; set; } 
     public string created_by { get; set; } 

    } 
+1

爲什麼你需要這樣做? – sr28

+1

你在詢問之前曾經嘗試/研究過什麼?這可以幫助你:https://codeblog.jonskeet.uk/2011/01/28/reimplementing-linq-to-objects-part-41-how-query-expressions-work/ –

+0

閱讀[問]並分享你的研究走向實際的錯誤。沒有錯誤,我們不能做太多事情。 – CodeCaster

回答

0

,因爲你正在編寫「s.sms_description」你得到錯誤,sms_description不是類sms_imported_trn_code的一部分,它是一個單獨的類,所以你需要寫db.sms_description

db.sms_imported_trn_code 
    .Where(s => !db.sms_description.Any(m => m.trn_code == s.trn_code)) 
    .Select(t => new {trn_code = t.trn_code }).ToList(); 
+0

謝謝你的工作。除了實體框架,你推薦的其他框架ORM是什麼?或者它仍然由Microsoft推薦。 –

+0

我對任何其他框架沒有太多經驗,我更喜歡使用實體框架。 – adhishspn