Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting scalar value back from a direct query
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Entity Framework
Title:
Getting scalar value back from a direct query
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01622028
Message ID:
01622028
Views:
54
UPDATE. Changed the code to get it into var result and then loop through it and got my string this way.

Hi everybody,

I'd like to execute a SQL Statement that should produce a single XML (string) value back. I am having troubles figuring out the correct way to get the value back.

This is what I've tried but got an error 'Sequence contains more than one element' in run-time:
string commandText = String.Format("select top (1) * from dbo.{0} where {1} = @PrimaryKey for xml path(''), elements absent ;", tableName, primaryKeyName);
                SqlParameter primaryKey = new SqlParameter("@PrimaryKey", SqlDbType.Decimal, 17);
                primaryKey.Value = (Decimal) id;
                originalState = _siriusContext.CoreContext.ExecuteStoreQuery<String>(commandText, primaryKey).Single().ToString();
Do you see how should I adjust that code?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform