This is a migrated thread and some comments may be shown as answers.

Using linqdatasource Inserting event

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrea Gorin
Top achievements
Rank 2
Andrea Gorin asked on 14 May 2010, 04:07 PM
What is the best way to insert a record using radgrid and LinqDataSource?

I'm using automatic operations (AllowAutomaticInserts) on a radgrid and one linqdatasource with "Inserting" event but the form go in error ! I have three key (not visibles to user) to add: 1 string, 1 integer and a integer calculated from database logic.

My piece of code:

protected

 

 

void ldsDestinazioni_Inserting(object sender, LinqDataSourceInsertEventArgs e)

 

{

 

 

Destinazione _nuovaDestinazione = e.NewObject as Destinazione;

 

_nuovaDestinazione.ID_Azienda =

 

SessionStore.Utente.ID_Azienda;

 

_nuovaDestinazione.ID_Cliente = (

 

int)ID_Cliente;

 

 

 

XSWDataContext _ordiniWeb = new XSWDataContext();

 

 

 

int _idDestinazione = 1;

 

 

 

var _destinazioni = _ordiniWeb.Destinazione.Where(d => (d.ID_Azienda == _nuovaDestinazione.ID_Azienda) &&

 

(d.ID_Cliente == _nuovaDestinazione.ID_Cliente));

 

 

if (_destinazioni.Count() > 0)

 

_idDestinazione = _destinazioni.Max(t => t.ID_Destinazione) + 1;

_nuovaDestinazione.ID_Destinazione = _idDestinazione;

_ordiniWeb.Destinazione.InsertOnSubmit(_nuovaDestinazione);

_ordiniWeb.SubmitChanges(System.Data.Linq.

 

ConflictMode.FailOnFirstConflict);

 

}


Please help!

Andrea 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 May 2010, 07:24 AM
Hello Andrea Gorin,

I would suggest that you review the following help article:

LINQ To SQL - binding and automatic CRUD operations

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Andrea Gorin
Top achievements
Rank 2
Answers by
Martin
Telerik team
Share this question
or