将DataGrid更新为EF

时间:2013-05-02 16:19:48

标签: c# wpf entity-framework entity-framework-4

我以这种方式将数据显示到DataGrid

var display = (from r in ve.Folders.Include("Hosting_Company1")
               select new RepoClass{ id = r.Folder_Id,name= r.Full_Name, hosName= r.Hosting_Company1.Housing_Name }).ToList();

dg1.ItemsSource = display;

XAML

<DataGrid CanUserAddRows="False" AutoGenerateColumns="False" Name="dg1">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=id, Mode=TwoWay}" Header="id"/>
        <DataGridTextColumn Binding="{Binding Path=name, Mode=TwoWay}" Header="Name" />
        <DataGridTextColumn Binding="{Binding Path=hosName, Mode= TwoWay}"  Header="company" />
    </DataGrid.Columns>
</DataGrid>

如何将数据更新为EF

1 个答案:

答案 0 :(得分:0)

如果ve是你的datacontext,那么你需要调用ve.SaveChanges()。我通常会将一个可观察的集合传递给datagrid,以便更改更易于管理。