Querying Entity Framework via Lambda Expression

 

 


In this article, we will write very flexible and easy queries using Lambda expression via Entity Framework. In today’s software world, as database programming is promoted to the external layer, the technologies we write queries over the organs become very important. Due to the rapid development of Entity Framework technology and the flexible dominance over Lamda expression objects, it began to be written on objects that are fairly easy to understand. Contrary to what you might think, these queries have very little performance loss with a good EF configuration (include use etc.).
We will use the Northwind db in queries. The inquiries and explanations are as follows.

Querying Entity Frame Work

  • Assign all the data in the table db to the product table

  • List products by name and assign to list

  • Products listed by name reverse printing

  • List the products tersten and catch the top 5 products and assign them to the list

  • Capture product with id si 5

  • Give the name of the product with ID 3

  • List of products with Category ID 5

  • Sort products with Category ID si 3 and Supplier ID si 2 by name Receive the first 5 record

  • Productname a list of products with a letter

  • List of items STARTING with a letter of product name

  • Productname list of products ending with a letter

  • Do you have a category

  • Category Is there a category with ID 5

  • Do you have a product that contains ‘taha’ in its name? Does not matter

  • Go to product line

  • Number of products

  • The number of Quantity Per Units in the product table (if column is null this column will not be added)

  • Total of product prices on product table

  • The most expensive product

  • Skip the first 5 products when sorted by name and list remaining products

  • Skip the first 5 products when sorted by name list 10 products

  • order specific to the shipcountry column in the order table (sql “select distinct o.ShipCountry // from Orders o”)

  • Returns the value of the product in the primary key field in the product table (returns productID // value 5)

 

 

if you have question do not forget to write from the chat button next to it or from the comment

You may also like...

6 Responses

  1. Onr says:

    Thanks bro, this entity-framework is boolshit but i had to use it sometimes. Whatever, thanks again.

  2. ASIM says:

    Bir sorum olacak code first ile oluşturduğum bir db var elimde ve
    Product.cs
    public int Id { get; set; }
    public string Name { get; set; }
    public Category Category { get; set; }
    Şeklinde tanımlı ve Category.cs
    public int Id { get; set; }
    public string Name{ get; set; }
    public List Product{ get; set; }
    şeklinde tanımlı. Ben Products’ları
    context.Products.ToList();
    bu şekilde çektiğimde Category kısımları boş geliyor. Bunu en düzgün yoldan nasıl çekerim. İki tabloyuda ayrı ayrı çekip birbirlerine eşitleyebilirim fakat benim merak ettiğim Product.cs ‘de Category Category property’si tanımladık bunu kullanarak kolay bir şekilde çekmemin bir yolu vardır diye düşünüyorum. Umarım derdimi anlatabilmişimdir.

  3. ASIM says:

    problemi çözdüm
    return context.Uruns.Include(“Category”).ToList();
    deyip Category.cs’de de
    public override string ToString()
    {
    return Name;
    }
    dediğim zaman geliyor.

Leave a Reply

Your email address will not be published. Required fields are marked *