Search code examples
c#databaselinqentity-frameworklinq-to-entities

Edit Data in DataGridView with LinQ to entity as datasource


Entity Models

This is a simple models that I am working on , three tables.
I need to Have a DataGridView that show the ClientID , ClientName , Current_Balance , Required , Expected , Paid , Difference_Req_Paid_Difference _Expe_Paid,DateWeekly and this DataGridView enable me to add new rows and to edit current
as DataSource I have used a LinQ like

visibledataGridView1.DataSource = context.Payments.Select(x => 
    new {  x.Client.ClientName,
x.ClientID,
x.Current_Balance,
x.Paid,x.Expected,
x.Required,
x.Difference_Exce_Paid,
x.Difference_Req_Paid 
});

but this only show thid doesn't allow me to add or to edit.


Solution

  • Problem Resolved with a little trick , with checking in the database if the current PaymentID , it will modifie by a sp that update the row in the database
    if not it will create a new object from Payment and add it to Payments.