Inloggen
 
 
 
 
    
Difference between Linq Objects and Linq Queries in a databinding scenario
Location: BlogsHenri Koppen - Developer    
Posted by: Henri Koppen 18-9-2008 10:31
I am currently developing an application using Linq in a databinding scenario. I like linq a lot being a set based command language, however some Linq/databinding behaviour is beyond me.
Tags: VB.NET Linq-to-SQL DataBinding.

I had to think some time to give this topic a title.

Look at this situation: I have a datagridview with a datasource property pointing to a bindingsource.

There's a difference between linking this datasource to a Linq-toSQL class and a Linq query.

Code:

Private db As New LinqDataContext

DataGridView1.DataSource = BindingSource1

' Situation A
BindingSource1.DataSource = db.Users

' Situation B
BindingSource1.DataSource = FROM u IN db.Users



If I delete an user in Situation A like this :
Code:

db.Users.DeleteOnSubmit(BindingSource1.Current)
db.SubmitChanges()
BindingSource1.DataSource = db.Users



The user will not dissappear immediately.

If I delete an user in Situation B like this
Code:

db.Users.DeleteOnSubmit(BindingSource1.Current)
db.SubmitChanges()
BindingSource1.DataSource = FROM u IN db.Users



The gridview is updated and will not show the deleted user.

I think that the difference is this: If you use a LINQ query it query's the database. If you just show the objects it looks into the object collection.

If you inspect the datasource of the bindingsource in debug mode you see that (when using a linq query) that the type is a "Database query", while db.Users as datasource is a Linq.Table (of users).

It has something to do with a bindingsource keeping it's own "administration".

Permalink |  Trackback
  
 
Weblogs
    
Archief
    
Zoeken
    
 
 
 
 
Copyright 2006-2009 by Arcencus
Privacy Statement | Terms Of Use