Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting scalar value back from a direct query
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
Getting scalar value back from a direct query
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01622028
Message ID:
01622028
Vues:
55
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
Répondre
Fil
Voir

Click here to load this message in the networking platform