BUY THIS BOOK
Add to Cart

Print Book $49.99


Safari Books Online

What is this?

Add to UK Cart

Print Book £30.99

What is this?

Looking to Reprint this content?

C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference

By Joseph Albahari, Ben Albahari
Price: $49.99 USD
£30.99 GBP

Cover | Table of Contents | Forum


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Wierd Linqpad Update Behavior
Terry Aney
post Apr 11 2008, 08:53 PM
Post #1


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



I am working on finalizing an implementation to support functionality simliar to: http://weblogs.asp.net/jeffreyzhao/archive...expression.aspx

I have the following LINQPad select statement:

CODE
var posts =
    from p in be_Posts
    where p.PostID == new Guid( "fb68266f-3ed6-4572-956b-8c2c54a30928" )
    select p;


When I run an update batch statement (don't worry I plan on blogging about this whole thing once I've ironed out everything), essentially the SQL command text to run will be:

CODE
UPDATE [be_Posts]
SET [Author] = @Author0

FROM [be_Posts] AS j0 INNER JOIN (

SELECT [t0].[PostID]
FROM [be_Posts] AS [t0]
WHERE [t0].[PostID] = @p0

) AS j1 ON (j0.[PostID] = j1.[PostID])

-- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [fb68266f-3ed6-4572-956b-8c2c54a30928]
-- @Author0: Input NVarChar (Size = 8; Prec = 0; Scale = 0) [Ann Aney]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8


Now, if I take that *exact* SQL to QueryEx or SQL Management Studio, it runs fine, but LINQPad returns an error of:

SqlException: Must declare the scalar variable "@Author0". Incorrect syntax near the keyword 'AS'.

LINQPad obviously display more information I can append if needed, but that is a start. Any ideas to why it wouldn't work only in LINQPad (admittedly I've yet to write a little test app to test it in stand alone C# application).
Go to the top of the page
 
+Quote Post
Terry Aney
post Apr 11 2008, 08:56 PM
Post #2


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



I 'mis-titled' this post. Sorry, dont' know if forum moderators want to fix it or not. Should be titled: Wierd Linqpad Update Behavior

This post has been edited by Terry Aney: Apr 11 2008, 08:56 PM
Go to the top of the page
 
+Quote Post
Joseph Albahari
post Apr 12 2008, 01:02 AM
Post #3


Active Member
**

Group: Members
Posts: 48
Joined: 16-February 08
Member No.: 90



Hi Terry

Maybe I'm missing something, but I don't see how that SQL could possibly execute in Management Studio or Query Express without first populating the parameters:

CODE
declare @Author0 nvarchar(100)
declare @p0 int

set @Author0 = 'Bloggs'
set @p0 = 123

UPDATE [be_Posts]
SET [Author] = @Author0

FROM [be_Posts] AS j0 INNER JOIN (

SELECT [t0].[PostID]
FROM [be_Posts] AS [t0]
WHERE [t0].[PostID] = @p0

) AS j1 ON (j0.[PostID] = j1.[PostID])


Regards

Joe
Go to the top of the page
 
+Quote Post
Terry Aney
post Apr 12 2008, 03:45 AM
Post #4


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



Well you are right. I made the assumption you'd 'assume' that. However I figured out the problem. When creating a command string for DataContext.ExecuteCommand(), the parameters must be named @p0-N. I was naming them 'other than' that, but also providing the same 'new' name in the DbCommand.

However, when calling ExecuteCommand() you pass only the string and object[] of values for params and it takes the object[] and creates new parameters @p0-N. Stupid mistake on my part. I almost have this extension tested thoroughly enough to blog about. You should be seeing something soon.
Go to the top of the page
 
+Quote Post
Joseph Albahari
post Apr 12 2008, 12:31 PM
Post #5


Active Member
**

Group: Members
Posts: 48
Joined: 16-February 08
Member No.: 90



QUOTE (Terry Aney @ Apr 12 2008, 11:45 AM) *
You should be seeing something soon.


Cool - will look forward to seeing it!

Cheers

Joe
Go to the top of the page
 
+Quote Post
Terry Aney
post Apr 14 2008, 08:33 AM
Post #6


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



Joe,

Here is the article: http://www.aneyfamily.com/terryandann/post...INQ-to-SQL.aspx

Also made apologies in there for ever suspecting LINQPad in the first place wink.gif

Enjoy.
Go to the top of the page
 
+Quote Post
Joseph Albahari
post Apr 17 2008, 02:10 AM
Post #7


Active Member
**

Group: Members
Posts: 48
Joined: 16-February 08
Member No.: 90



QUOTE (Terry Aney @ Apr 14 2008, 04:33 PM) *


Just read the article - it looks really useful.

Highly recommended!

Joe
Go to the top of the page
 
+Quote Post
Terry Aney
post Apr 21 2008, 03:38 AM
Post #8


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



Thanks Joe. Couple things. First, is it worth you changing the title of the post as it is a bit misleading? Not sure if you want to or not.

More importantly, I've found and posted a new fix in the code. You can read about the issue and the fix at LINQ to SQL Batch Updates/Deletes: Fix for 'Could not translate expression'.
Go to the top of the page
 
+Quote Post
Sarah Kim
post Apr 25 2008, 02:44 AM
Post #9


Active Member
***

Group: Administrators
Posts: 82
Joined: 12-November 07
Member No.: 6



Hi Terry,

I updated the topic title as you suggested so it's clear for other people.

Thanks for pointing that out!
Sarah
Go to the top of the page
 
+Quote Post
Terry Aney
post May 5 2008, 06:20 AM
Post #10


Active Member
**

Group: Members
Posts: 10
Joined: 25-March 08
Member No.: 169



QUOTE (Sarah Kim @ Apr 24 2008, 09:44 PM) *
Hi Terry,

I updated the topic title as you suggested so it's clear for other people.

Thanks for pointing that out!
Sarah


I don't even remember what the 'original' title was, but I think you updated it to 'Wierd Linqpad Update Behavior' (or at least that is title currently showing). Nothing really wierd/wrong with LINQPad...I made a mistake. The post has evolved more into a 'Batch Updates and Deletes with LINQPad/LINQ to SQL'. Again, you can review if you want to change it to something along those lines.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 28th August 2008 - 12:22 AM