我有两个表,它们具有多对多关系,称为“按钮”和“图块”,如下所示:
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] 删除。
我来说两句