Many-to-many sorting in Entity Framework -


In my application there is a unit framework model that has many relation-to-many relationships, such as the following:

  Product Group: Scalar: ID, Name Navigation: Product Group Product: Scalar: Id, Sku, Details, etc. Navigation: Product group Product product group: Scaler: Product group IID, Product ID, Position Navigation: Product, Product group  

Note that the intermediate table has a scalar property called status, In which the product should be displayed within the product group.

How would you write a LINQ query, which is a list of products sorted by the position property in a given product group? If I am writing good ol 'sql, then I will write something like this:

SELECT p.Id, p.Sku, p.Description from product P INNER JOIN ProductGroupProduct pgp ON p.Id = Pgp.ProductId WHERE pgp.ProductGroupId = @MyProductGroupId by command pgp.Position

but I can not understand LINQ.

Um, your SQL will not work, because no ProductGroup.Position < / P>

but I think you want:

  var q = reference from pgp. Product group products where pgp.ProductGroup.Id == ID select pgp.Position pgp.Product by order;  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -