Linq to Sql, how to check if a given table/class is in the changeset of the DataContext -


I am parsing an XML-file using LinqToXSD I insert elements in XML into related tables in a database I'm using Linq to

I

  DB & Lt; Table & gt; Using several different tables / elements in the datacentext; InertOnSubmit (table);  

Where Tables can be around 75 different tables.

The XML is full of duplicates, and I would like to check if the element already given in XML is added to the changes in DataContext.

Is there a normal way of doing this? The way I'm doing this, it is now including writing code for each separate table, so I think I can somehow remove a method in some other way and write this code once.

To parsize the XML I have a method for each element in the XML that matches a table in the database. In the next two ways, each type of XML-Elements is handled.

Private Static tbl_trackname ParseTrackName (TRACKNAMEType tRACKNAMEType) {tbl_trackname tableTrackName = new tbl_trackname (); TableTrackName.code = tRACKNAMEType.code; TableTrackName.text = tRACKNAMEType.text; DB.tbl_tracknames.InsertOnSubmit (tableTrackName); Return tabletrekname; } Private static tbl_track parseractic (track type typewrite) {tbl_track tableTrack = new tbl_track (); TableTrack.trackID = int.Parse (tRACKType.trackid); TableTrack.tbl_organization = ParseOrganisation (tRACKType.organization); TableTrack. Tbl_trackname = ParseTrackName (tRACKType.trackname); TableTrack.tbl_nation = Parsation (tRACKType.country); DB.tbl_tracks.InsertOnSubmit (tableTrack); Return Table Track; }

The first method contains the rows in a table named tbl_trackname, the rows inserted in the second table are named tbl_track.

There is a missing code code which checks if a track, or track name is already entered into the datacentext. I should also check that it is already in the database but it is just a line of code, so I can do this with every purse XXX () method.

OK, you probably can do something with dataContext.GetChangeSet (). Inserts.OfType & lt; Foo & gt; () ? Maybe in any or

Can you give more of an example?


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -