0

I am using linq to sql , and I return a queryable result from linq to sql :

var qry = from p in table select p;

Then I use this to bind to a xtragrid:

GridControl.DataSource = qry;

Then If I edit the records in xtraGrid, I just need to call dataContext.submitChanges() to submit the changes back to database.

My question is :

Am I possible to just add new records into the qry result, and after that I only need to call dataContext.submitChanges(), then linq can create new records on database automatically ?

Is that possible ? Can someone point me the right direction ? Thanks in advance !

1
  • If you would already put the data dynamically into the query and afterwards give this query to your DataGrid. How should your Grid know that there are any changes to submit?
    – Oliver
    Jul 23, 2010 at 10:06

2 Answers 2

1

Shot answer would be no. You need to call the Add method on the table property on your context.

Something like this:

var qry = from p in myDataContext.Table select p;

GridControl.DataSource = qry;

myDataContext.Table.Add(newRecord); // This is how to add new recrod

dataContext.submitChanges();

Read more here: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

1
0

You are aware that if you use a LinqDataSource instead of giving a query to your Grid's DataSource property, SubmitChanges, Add, Delete & friends will be called automatically for you, right? If you need to display a subset of the table, you can still override the LinqDataSource's Selecting event to feed it your own query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.