mardi 24 février 2015

Error converting string to GUID in c#

I am using the following code for performing a delete operation via EF code first using a inline query internally



void IRepository<T>.Delete(params Guid[] ids)
{
var sql = string.Format("UPDATE {0} SET [IsDeleted] = 1 WHERE [Id] IN (@ids) ", GetTableName());
string sep = String.Join(", ", ids.Select(x => "'" + x + "'"));
var sqlParams = new Object[]
{
new SqlParameter("ids", string.Join(",",sep)),
};
DataContext.Database.ExecuteSqlCommand(sql, sqlParams);
}


Now when I execute the command it gives me



conversion failed when converting from a character string to uniqueidentifier


error.


Hiwever when I run the query in sql say.



UPDATE [dbo].[Table] SET [IsDeleted] = 1 WHERE [Id] IN ('20Cr0BCA-6EBB-E411-A04B-BC305BA8C713','506c79c1-6ebb-e411-a04b-bc305ba8c733')


it works fine.


Is this possible to do this way ?Or what am I doing wrong ?


Aucun commentaire:

Enregistrer un commentaire