the LinqToSQL is a lie(objectreference.net)

submitted by Vort3XVort3X(1335) 3 years, 9 months ago

LinqToSql is amazing! I've been working with it for the past week and loving every moment. However i've noticed somethig weird, it lies to me about the SQL it's generating. Here is my example...

4 comments |category: |Views: 33

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by yatendrayatendra(0) 3 years, 9 months ago 0

hmmmm

Reply

posted by zigamorphzigamorph(3314) 3 years, 9 months ago 0

It is not lying you have two different queries, one query that you displayed on the blog, and one related query that only gets called when you request the data. You examining the object with the debugger calls this data. Use SQL Profiler you will see two different queries. ;(

Reply

posted by Vort3XVort3X(1335) 3 years, 9 months ago 0

On my example I'm binding to a list view and I am requesting the data by doing Eval("CustomerLINQ.CustomerName") but it doesn't show me the actual generated SQL it's running which was my point.

What your saying the only way to see what LinqToSQL it's actually running is by using SQL Profiler.

Reply

posted by zigamorphzigamorph(3314) 3 years, 9 months ago 0

Naz, that is correct it is because two different SQL queries are getting run. One for the Quote object and one for the Customer object, the Quote object is the top level so that is all that is being shown. If you are definitely using both and to cut down on round trips you want to consider the following.

from q in db.QuoteLINQs
where q.QuoteID.Equals(10)
select q, q.CustomerLINQ.CustomerID;

This will return both at the same time and should result in the SQL you are looking for. You can also use a feature in the DataContext that allows you to bind all references at the same time, however that is overkill for just getting back a CustomerID.

Reply

information Login or create an account to comment on this story