【发布时间】:2014-02-20 15:06:44
【问题描述】:
我的 ObservableCollection 终于提取了数据,但现在它没有保存编辑。
这是我的代码:
public void FillDataGrid(Guid corporationId)
{
var query = from s in entity.Sources
where s.CorporationId == corporationId
select new SourceItem
{
CorporationId = s.CorporationId,
Description = s.Description,
IsActive = s.IsActive,
Name = s.Name,
SourceId = s.SourceId,
TokenId = s.TokenId
};
SoureItemCollection = new ObservableCollection<SourceItem>(query);
SourceDataGrid.ItemsSource = SoureItemCollection;
SourceDataGrid.Columns[2].Visibility = Visibility.Hidden;
SourceDataGrid.Columns[0].IsReadOnly = true;
SourceDataGrid.Columns[1].IsReadOnly = true;
}
这是我要绑定的类:
public class SourceItem
{
private Guid _corporationId1;
private string _description;
private bool _isActive;
private string _name;
private Guid _sourceId;
private Guid _tokenId;
public Guid CorporationId
{
set
{
_corporationId1 = value;
onPropertyChanged(this, "CorporationId");
}
get { return _corporationId1; }
}
public string Description
{
set
{
_description = value;
onPropertyChanged(this, "Description");
}
get { return _description; }
}
public bool IsActive
{
set
{
_isActive = value;
onPropertyChanged(this, "IsActive");
}
get { return _isActive; }
}
public string Name
{
set
{
_name = value;
onPropertyChanged(this, "NAme");
}
get { return _name; }
}
public Guid SourceId
{
set
{
_sourceId = value;
onPropertyChanged(this, "SourceId");
}
get { return _sourceId; }
}
public Guid TokenId
{
set
{
_tokenId = value;
onPropertyChanged(this, "TokenId");
}
get { return _tokenId; }
}
// Declare the PropertyChanged event
public event PropertyChangedEventHandler PropertyChanged;
// OnPropertyChanged will raise the PropertyChanged event passing the
// source property that is being updated.
private void onPropertyChanged(object sender, string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
}
}
还有保存:
private void Save_Click(object sender, RoutedEventArgs e)
{
entity.SaveChanges();
}
我想在保存之前将 ObservableCollection 绑定回实体吗?如果是这样,我该怎么做?
【问题讨论】:
标签: c# linq entity-framework observablecollection