Inner join ile update sorgusu

KULLANICI tablosunda ADSOYAD boş olan kayıtlar için ESKI_KULLANICI tablosundaki ADSOYAD ile günceller.

UPDATE KULLANICI 
SET KULLANICI.ADSOYAD = ESKI_KULLANICI.ADSOYAD 
FROM NEW_KULLANICI AS KULLANICI 
INNER JOIN OLD_KULLANICI AS ESKI_KULLANICI 
       ON KULLANICI.KIMLIKNO = ESKI_KULLANICI.KIMLIKNO 
WHERE KULLANICI.ADSOYAD is null 

Entity üzerinde sql sorgu çalıştırma

var query = “SELECT * FROM Meters WHERE CustomerId = ” + customer.sno + ” ORDER BY MeterName”;
var Meters = entity.Database.SqlQuery<Meter>(query).ToList();

 

context.Database.SqlQuery<myEntityType>(
    "mySpName @param1, @param2, @param3",
    new SqlParameter("param1", param1),
    new SqlParameter("param2", param2),
    new SqlParameter("param3", param3)
);

context.Database.SqlQuery<MyEntityType>("mySpName @param1 = {0}", param1)

return context.Database.SqlQuery<myEntityType>("mySpName {0}, {1}, {2}",
new object[] { param1, param2, param3 });

//Or

using(var context = new MyDataContext())
{
return context.Database.SqlQuery<myEntityType>("mySpName {0}, {1}, {2}",
new object[] { param1, param2, param3 }).ToList();
}

//Or

using(var context = new MyDataContext())
{
object[] parameters =  { param1, param2, param3 };

return context.Database.SqlQuery<myEntityType>("mySpName {0}, {1}, {2}",
parameters).ToList();
}

//Or

using(var context = new MyDataContext())
{  
return context.Database.SqlQuery<myEntityType>("mySpName {0}, {1}, {2}",
param1, param2, param3).ToList();
}