2

我的 DB 2 表中有:

  1. 文档(Document_Id,document_Name)

  2. Person_Documents (person_ID ,Documet_Id document_Done)

我使用实体框架,我想用DataGrid数据填充document_Namedocument_Done

我尝试了以下没有结果:

      vagEntities projectE = new vagEntities();
      var doc = from c in projectE.Person_Documents                   
          join cw in projectE.Documents on c.Document_Id equals cw.Document_Id
          where c.Person_Id == 150
          select c;

      DocGrid.ItemsSource = doc;

请问,我哪里错了?在 xaml 我写这个

                <DataGridTextColumn Binding="{Binding Path=Document_Name}" MinWidth="100"   Header="document"  />

            <DataGridCheckBoxColumn  Binding="{Binding Path=Document_done}" Header="Do" />
4

2 回答 2

3

我认为您希望将结果投影到这样的匿名类型:

更新 - 项目到具体类

public class NameAndDone {
  public string document_Name { get; set; }
  public bool document_Done { get; set; }
}

var doc = from c in projectE.Person_Documents
          join cw in projectE.Documents on c.Document_Id equals cw.Document_Id
          where c.Person_Id == 150
          select new NameAndDone {
            cw.document_Name,
            c.document_Done
          };
于 2012-11-06T17:35:34.773 回答
0

我会这样做

  vagEntities projectE = new vagEntities();
  var doc = from c in projectE.Person_Documents                   
      from cw in projectE.Documents where c.Person_Id == 150 && c.Documents.Contains(cw)
      select c;

  DocGrid.ItemsSource = doc;
于 2012-11-06T17:38:48.030 回答