Question Linq short comings?

mbb

Well-known member
Joined
Jun 3, 2009
Messages
52
Programming Experience
10+
I have to say, I started using Linq to SQL a couple of months ago, but it is a very powerful feature.

Just a couple of queries.

1.
Linq apparently keeps a memory copy of the objects it maps, but it is recommended that changes to those memory objects should be commited using submitallchanges() at the earliest opportunity.

In my application, I essentially wanted to keep a memory copy of my tables to add, update and delete to and synchronise the memory copy with a load and save operation. I've written a pattern that will received the row type - an extended version of the generated sqlmetal class - which handles all the synchronisation stuff. Am I barking up the wrong tree, or am I correct to respect the advice on the correct usage of the generated code and implement my own synchronisation routines?

2.
Is it me or does the generated class for a row seem incomplete? The On<Field>Changing event doesn't allow any parameters to be passed (like field name), but the On<Field>Changed does.
 
I think I found another problem with linq to sql thats worth mentioning.

I have a generic class that processes say add operations onto a table so the code looks something like this:

VB.NET:
Dim row as RowClass = listOfRecords(index)

db.GetTable(of RowClass).InsertOnSubmit(row)

db.SubmitAllChanges()

Where RowClass is the placeholder for the specific class.

So it seems Linq to SQL is very particular about the object you pass to it in the InsertOnSubmit.

My code showed that if I pass an object of the RowClass (with my own extended definitions), everything was fine.

But, if I tried to use a class that was inherited from the RowClass, the SubmitAllChanges() threw an object is null exception. I'm guessing that the InsertOnSubmit(row) checked the object type received and rejected the inherited object, leaving a null object reference lying around.

I did try to use a TryCast on the inherited type to convert it to the base type (RowClass), but frustratingly the trycast just returned the inherited class!

Anyway, there it is. I will code around this problem, but any suggestions and/or solutions would be welcome.
 
Back
Top