2016-09-06 4 views
-4

어떻게하면 다음과 같은 linq를 sql에서 람다 식으로 변환 할 수 있습니까? 감사.Linq 쿼리를 람다로 변환

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

내 모델 클래스는 "s.sms_description"를 작성하기 때문에 오류를 얻고있다

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

[ask]를 읽고 연구 내용을 공유하십시오. 실제 오류쪽으로. 오류가 없으면 우리는 많이 할 수 없습니다. – CodeCaster

답변

0

이하, 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