简体   繁体   English

实体框架使用.Include绑定到查询

[英]Entity Framework Binding to a Query with a .Include

Ok I am trying to do 好吧,我想做

from s in _db.Students.Include("Advisor") orderby s.LastName select s;

once I get that working there will be several more Includes, but I need to figure this out first. 一旦我知道可以使用,将会有更多的包含,但是我需要首先弄清楚。 Basically I have no idea how to bind text boxes to the included advisor information. 基本上我不知道如何将文本框绑定到所包含的顾问信息。 My bindings for the main student data work, but not for the advisor. 我对主要学生数据的绑定,但对顾问的绑定。 The bindings look like: 绑定看起来像:

Text="{Binding Path=Advisor.AcadAdv}"

Also the Main grid contains the DataContext to my CollectionView of students objects. 此外,主网格还包含DataContext到我的学生对象的CollectionView中。

Advisor is a table with an id a foreign key to student and 5 text fields with names of the advisors in them. 顾问程序是一个表,其ID为学生的外键,并且包含5个带有顾问程序名称的文本字段。

According to details you provided, you can: 根据您提供的详细信息,您可以:
1) specify item in the binding path (something like this: {Binding Path=Advisor[0].AcadAdv}) 1)在绑定路径中指定项目(类似这样的内容:{Binding Path = Advisor [0] .AcadAdv})
2) bind Advisor property to any ItemsControl 2)将Advisor属性绑定到任何ItemsControl
3) make a view model, which will have Advisor property as a first item of collection 3)创建一个视图模型,该模型将把Advisor属性作为集合的第一项
4) make Advisor a scalar property, not a collection (this will require entity model changes). 4)将Advisor设为标量属性,而不是集合(这将需要更改实体模型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM