Hi,
In mvc i am working with database first approach,in this after adding tables, it will generate edmx file.By using this ,can i do dynamic query?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jul 17, 2014, 1:31 AM
Hi,
this can be achieve by Building Predicate dynamically...
for example, I have department master table and I want to retrieved data from this table where department id = 1 then code like....
using (Entities Context = new Entities())
{
ParameterExpression c = Expression.Parameter(typeof(DepartmentMaster), "dep");
Expression left = Expression.Property(c, "DepartmentId");
Expression right = Expression.Constant(1);
Expression exp = Expression.Equal(left, right);
var queryableData = Context.DepartmentMasters.Where(Expression.Lambda>(exp, c).Compile()).ToList();
}
also refer
http://drc.ideablade.com/xwiki/bin/view/Documentation/dynamic-projection
http://msdn.microsoft.com/en-us/library/bb882637.aspx
hope this will help you.
Ramesh MaruthiPosted Jul 16, 2014, 11:58 AM
var sasiItems = from p in ctx.sasiItems
where p.Category.CategoryName == "Beverages"
Select new
{ID = p.ProductID, Name = p.ProductName,NumOrders = p.OrdersDetails.Count };