我正在从一个实体对象填充一个网格,它可以很好地显示数据。当我进行更改并将其保存回来时,没有任何更新。
这是我的代码:
在我的加载事件中:
var query = from c in _entities.PaymentTypes
where c.CorporationId == _currentcorp.CorporationId
select
new DataBindingProjection
{
PaymentTypeId = c.PaymentTypeId,
CorporationId = c.CorporationId,
TokenId = c.TokenId,
IsActive = c.IsActive,
Description = c.Description,
CashChargeCodeType = c.CashChargeCodeType,
SortOrder = c.SortOrder,
ExcludeCreditCode = c.ExcludeCreditCodes,
IsUpdated = c.IsUpdated,
IsAdded = c.IsAdded,
ClearUpdatedAndAdded = c.ClearUpdateAndAdded
};
dataGridView_PaymentTypes.DataSource = query.ToList();
我的课:
private class DataBindingProjection
{
public Guid PaymentTypeId { get; set; }
public Guid CorporationId { get; set; }
public Guid TokenId { get; set; }
public bool IsActive { get; set; }
public string Description { get; set; }
public int CashChargeCodeType { get; set; }
public int SortOrder { get; set; }
public int ExcludeCreditCode { get; set; }
public bool IsUpdated { get; set; }
public bool IsAdded { get; set; }
public bool ClearUpdatedAndAdded { get; set; }
}
在按钮中保存更改:
private void button_SaveChanges2_Click(object sender, EventArgs e)
{
button_SaveChanges2.Enabled = false;
_entities.SaveChanges();
timer1.Enabled = true;
button_SaveChanges2.Enabled = true;
}
我究竟做错了什么?
回应 bmused:
在类级别定义:
private SuburbanPortalEntities _entities;
在我的负载中定义:
var bs = new BindingSource();
_entities.PaymentTypes.Where(x => x.CorporationId == _currentcorp.CorporationId).Load;
bs.DataSource = _entities.PaymentTypes.Local.ToBindingList();
dataGridView_PaymentTypes.DataSource = bs;
它显示它无法加载符号 Load 和 Local: