복붙노트

[SQL] 엔티티 프레임 워크 - 제 사용량 속성

SQL

엔티티 프레임 워크 - 제 사용량 속성

내 데이터베이스에 대한 질의에 "정상"WHERE 및 IN 절을 사용하여 다양한 분야로 일부 엔티티를 필터링해야하지만 나는 EF와 함께 그렇게하는 방법을 모르겠어요.

이 접근 방식입니다 :

데이터베이스 테이블

Licenses
-------------
license INT
number INT
name VARCHAR
...

EF에서 SQL 쿼리를 원하는

SELECT * FROM Licenses WHERE license = 1 AND number IN (1,2,3,45,99)

EF 코드

using (DatabaseEntities db = new DatabaseEntities ())
{
    return db.Licenses.Where(
        i => i.license == mylicense 
           // another filter          
        ).ToList();
}

나는 모든과 시도가 있지만 나는 EF와 함께 그렇게하는 방법을 몰라했다.

어떻게 EF에서이 쿼리를 할까?

해결법

  1. ==============================

    1.

    int[] ids = new int[]{1,2,3,45,99};
    using (DatabaseEntities db = new DatabaseEntities ())
    {
        return db.Licenses.Where(
            i => i.license == mylicense 
               && ids.Contains(i.number)
            ).ToList();
    }
    

    SHOULD 작업

  2. from https://stackoverflow.com/questions/13342817/entity-framework-attribute-in-clause-usage by cc-by-sa and MIT license