我從一個實體對象填充一個網格,它顯示數據正常。當我做出更改並將其保存後,沒有任何更新。datagridview綁定到實體沒有更新數據庫
這裏是我的代碼:
在我的加載事件:
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;
據表明它不能加載符號加載和本地:
爲什麼要突出到具有與您的實體完全相同的屬性的另一種類型? – 2013-05-10 22:00:02
測試,我嘗試了幾個不同的想法,我結束了這一點。授予它不需要,但我離開了它。 – ErocM 2013-05-11 03:43:49
should't'Load'是'Load()'? – 2013-05-21 06:11:33