Tôi đang điền một lưới từ một đối tượng thực thể và nó đang hiển thị dữ liệu tốt. Khi tôi thực hiện thay đổi và lưu lại, không có gì đang cập nhật.datagridview ràng buộc với thực thể không cập nhật cơ sở dữ liệu
Đây là mã của tôi:
Trong trường hợp tải của tôi:
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();
lớp của tôi:
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; }
}
Trong nút để lưu các thay đổi:
private void button_SaveChanges2_Click(object sender, EventArgs e)
{
button_SaveChanges2.Enabled = false;
_entities.SaveChanges();
timer1.Enabled = true;
button_SaveChanges2.Enabled = true;
}
Tôi đang làm gì sai?
Để đối phó với bmused:
Defined ở cấp lớp:
private SuburbanPortalEntities _entities;
quy định tại tải của tôi:
var bs = new BindingSource();
_entities.PaymentTypes.Where(x => x.CorporationId == _currentcorp.CorporationId).Load;
bs.DataSource = _entities.PaymentTypes.Local.ToBindingList();
dataGridView_PaymentTypes.DataSource = bs;
Nó cho thấy rằng nó không thể tải biểu tượng Load và Địa phương:
Tại sao các bạn chiếu sang loại khác có các thuộc tính giống hệt nhau của pháp nhân của bạn? –
thử nghiệm, tôi đã thử một số ý tưởng khác nhau và tôi đã kết thúc với điều này. Cấp nó không cần thiết nhưng tôi đã bỏ nó. – ErocM
should't 'Load' là' Load() '? –