Last post Dec 09, 2011 03:29 AM by Young Yang - MSFT
Dec 07, 2011 10:50 AM|issacthiyagrajan|LINK
iam having enum values like
Public Enum List Name = 1 Description = 2 Status = 3 End Enum
these name,Description ,Status are column names that iam showing in the pae, iam creating web.UI. Table to show the details
on this table iam using sorting, with column name, so iam passing the enum value to a function on that function iam sorting with the column value
Public Sub BindTable(Optional ByVal SortColumn As List = List.Name)
iam using linq query on this iam wrting like from p in db.list where id = listid order by SortColumn.Tostring Ascending
but it was not sorting and it says error that .toString is not recoginised, then i remove the toString then also it is not working
please help me regarding this
Dec 07, 2011 11:53 AM|Pankaj.Sharma|LINK
What kind of db.list object is? Is it a collection i.e. List<>?
Modify your code to frame the query as follows.
static object GetColumn(List l, P p)
The P(capital one) is the type of variable p in linq query. And modify the query as follows
from p in db.list where id = listid order by GetColumn(SortColumn, p) Ascending select p;
Hope this help you.
Dec 07, 2011 12:20 PM|issacthiyagrajan|LINK
i run your code but an error like this,
LINQ to Entities does not recognize the method 'System.Object GetColumn(Coupon_List_Sort, cWyze_Azure_Web_app.tblADAGCoupon)' method, and this method cannot be translated into a store expression.
is showing when i am executing...
Dec 07, 2011 12:49 PM|Pankaj.Sharma|LINK
You need to slightly modify your code as per your requirement, as you have not provided your code for review. But it looks like you are firing the linq query on a datatable object, right?
If yes then you need to modify your query in a similiar fashion
var sorted = from item in table.AsEnumerable()
where item.Field<string>("Status") == "false"
Hope you have got the point.
Dec 07, 2011 02:11 PM|issacthiyagrajan|LINK
my enum class is
Public Enum Coupon_List_Sort CouponName = 1 CouponDescription = 2 Status = 3 ExpiredDays = 4 Brandid = 5 End Enum
iam having a function
Public Sub BindTable(Optional ByVal SortColumn As Coupon_List_Sort = Coupon_List_Sort.CouponName, Optional ByVal Sort As Sort_Order = Sort_Order.ASC)
coupon = (From p In dbase.tblADAGCoupons Where p.ADAGId = nAgencyId Order By SortColumn Descending Select p).ToList()
dbase is nothing but the entity class(using object context)
in the BindTable function sortColumn contains the value of enum class
if i click the 1st column, columnName(1) is passed in the SortColumn, i want to take the value to the "Order By SortColumn" and i want to sort it, but linq query said that there is no column name "SortColumn " in dbase.tblADAGCoupons
this is the problem for me
i need to pass the enum value to the linq query
i think u can understand the problem
Dec 09, 2011 03:29 AM|Young Yang - MSFT|LINK
You can read this post, it is a simple sample about how to map an enum.
Hope this helpful