다음과 같이 다 대다 관계가있는 Buttons 및 Tiles라는 두 개의 테이블이 있습니다.
Buttons *-----------
ButtonID |
Title |
|
Tiles *-----------
TileID
Title
이제 다음과 같은 쿼리를 시도하고 있습니다.
b = new ObservableCollection<Buttons>(from x in db.Buttons
where x.Tile == SelectedTileObj
select x);
하지만 아래와 같이 오류가 발생합니다.
Unable to create a constant value of type 'Data.Tiles'.
Only primitive types or enumeration types are supported in this context.
TileID
기본 키 라고 가정하면 다른 접근 방식을 취할 수 있습니다.
탐색 속성을 사용하여 위 타일과 관련된 버튼을 가져옵니다.
var tiles = db.Tiles.Where(t => t.TileId == SelectedTileObj.TileId);
// t.Buttons should be the navigation property for retrieving associated buttons
var buttons = tiles.SelectMany(t => t.Buttons);
var b = new ObservableCollection<Buttons>(b);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다