score:5
add following line to your query
var pagedquery = data.skip(pageindex * pagesize).take(pagesize);
the data variable is iqueryable, so you can put add skip & take method on it. and if you have relationship between product & variant, you donot really require to have join explicitly, you can refer the variant something like this
iqueryable<productinventory> data =
from inventory in objcontext.productinventory
where inventory.productid == productid && inventory.storeid == storeid
orderby inventory.variant.sortorder
select new()
{
property1 = inventory.variant.variantid,
//rest of the properties go here
}
pagedquery = data.skip(pageindex * pagesize).take(pagesize);
score:0
you would simply use your skip(itemsinpage * pageno).take(itemsinpage)
to do paging.
score:1
my answer here based on the answer that is marked as true but here i add a new best practice of the code above
var data= (from c in db.categorie.asqueryable().join(db.categorymap,
cat=> cat.categoryid, catmap => catmap.childcategoryid,
cat, catmap) => new { category = cat, categorymap = catmap })
select (c => c.category)
this is the best practice to use the linq to entity because when you add asqueryable() to your code; system will converts a generic system.collections.generic.ienumerable to a generic system.linq.iqueryable which is better for .net engine to build this query at run time
thank you mr. khumesh kumawat
score:8
define the join in your mapping, and then use it. you really don't get anything by using the join
method - instead, use the include
method. it's much nicer.
var data = objcontext.productinventory.include("variant")
.where(i => i.productid == productid && i.storeid == storeid)
.orderby(j => j.variant.sortorder)
.skip(x)
.take(y);
Source: stackoverflow.com
Related Query
- Entity Framework 4 - What is the syntax for joining 2 tables then paging them?
- What is the method syntax for this LINQ, is it a join, and if not then what is it?
- Joining or Including multiple tables with Entity Framework Core LINQ to Entities - One to Many and then Many to One
- What are the Java equivalents to Linq and Entity Framework
- Joining tables from two databases using entity framework
- Entity Framework appears to be needlessly joining the same table twice
- Access all of the data after joining two tables and group them using linq
- What is the best way to write queries in Entity Framework
- Entity Framework Core : LINQ advise needed on better approach using include for relational tables
- Joining multiple tables using Entity Framework
- Efficient joining the most recent record from another table in Entity Framework Core
- What are the major differences between Data Access Application Block, NHibernate, ADO.NET Entity Framework and LINQ to SQL?
- What is the simplest way to implement an Entity Framework 6 Add-or-Update method
- System.Linq.Dynamic not working for the Entity Framework
- Entity Framework 4 generated queries are joining full tables
- What should you use for joining in LINQ, Query syntax or method syntax?
- What can be the code for someIEnumerable.Select extension method?
- joining two tables in entity framework
- The result of a query returns the same value for COLUMN_NAME from an Entity Framework query, which doesn't make sense
- Syntax for Entity Framework .Include()
- LINQ entity data model generated code error - The type 'DBContexts.Category' already contains a definition for 'ID'
- Entity Framework Code First override onModelCreating() for TPT Inheritance Screwing Up Identity User and Role Models
- If Entity Framework is meant to work with POCOs, then why the dependency on IObjectSet?
- What is a possible interface to return for Entity framework entity classes?
- What is the linq select syntax to check for xml data with null elements?
- linq: what is the expression tree syntax for cross join
- What is the best way in assigning foreign key when using entity framework & LINQ to Entities?
- what is the right syntax for OrderByDescending with condition?
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- Converting a Linq expression tree that relies on SqlMethods.Like() for use with the Entity Framework
More Query from same tag
- Convert aggregate SQL query to LINQ
- LINQ: Get all selected values of a CheckBoxList using a Lambda expression
- What would be Linq for Following
- How to get the name of the first worksheet linqtoexcel?
- How to select and iterate through a XML xElement node from attribute values?
- How to do a grouped distinct in linq
- Why is this LINQ to EF query not working?
- ElementAt(index) on ICollection<T>
- Check if List<Int32> values are consecutive
- How to test post method in fiddler?
- C# LINQ Query to List of Nested JSON
- Is it better to use Enumerable.Empty<T>() as opposed to new List<T>() to initialize an IEnumerable<T>?
- EF6 Linq Query .Include only returning first entry of child table
- Getting a DateTime value using LINQ
- Use LINQ Query with in-line function - sorted by function
- DateTime Conversion in Entity Framework
- find non intersecting data set with linq
- Writing left join in linq query with 5 table
- Linq grouping multiple where condition
- c# Linq query to group items by group and then sub-group
- How to match a sequence in a List with LINQ?
- LINQ List Contains Another List (Contiguous)
- Conditional combined sum in LINQ
- LINQ-to-Entities with 8-bit ASCII data
- Linq with group by returning count 1 when when it should be 0
- How to get items that are and are not in a list
- Docusign XML C# LINQ enumeration yielded no results
- Fluent Assertion: Dictionary Should BeEquivalentTo Excluding Property on Dictionary Value
- return value in function
- Linq query with cartesian (wanted) and min/max in where clause