static void Main(string[] args) { // using (var db = new NorthwindContext()) // { // //miami'de yaşan customer bilgileri gelir. // var city = "Miami"; // var customers = db.Customers // .FromSqlRaw("select * from customers where city={0}", city).ToList(); // foreach (var item in customers) // { // Console.WriteLine(item.FirstName); // } // } /////////////////////////////////////////////// // bu sayede HasColumnName gibi bilgileri context sınıfından ezdik. using (var db = new CustomNorthwindContext()) { // Müşterilerin sipariş sayıları veriliyor. var customers = db.CustomerOrders .FromSqlRaw("select c.id,c.first_name,count(*) as count from customers c inner join orders o on c.id=o.customer_id group by c.id").ToList(); foreach (var item in customers) { Console.WriteLine("customer id: {0} firstname: {1} order count: {2}", item.CustomerId, item.FirstName, item.OrderCount); } } }
static void Main(string[] args) { using (var db = new CustomNorthwindContext()) { //var sonuc = db.Database.ExecuteSqlRaw("delete from products where productId=81"); //var sonuc = db.Database.ExecuteSqlRaw("update products set unitprice=unitprice*1.2 where categoryId=4"); //var query = "4"; //var products = db.Products.FromSqlRaw($"select * from products where categoryId={query}").ToList(); var products = db.ProductModels.FromSqlRaw("select ProductId,ProductName,UnitPrice from Products").ToList(); foreach (var item in products) { Console.WriteLine(item.Name); } } Console.ReadLine(); }