I have a problem here.In my database I store member status in 1 and 0, when it come to my gridview I need change 1 and 0 to active and inactive. My company is using Linq, so I must follow. I wrote in this style, I calling a changeToWord() function to change
1 and 0 to active and inactive.
var q=from a in db.members
select new{
mem_name=a.name,
status=ChangeToWords(a.status)
}
It compiles with no error, but when I execute the page, it prompt out a error message to me. Thanks.
the error msg is "Could not translate expression 'value(ASP.gui_member_List_aspx).changeToWord(a.Status)' into SQL and could not treat it as a local expression."
aisy
0 Points
22 Posts
calling function in linq query
Apr 08, 2010 09:42 AM|LINK
hey all.
I have a problem here.In my database I store member status in 1 and 0, when it come to my gridview I need change 1 and 0 to active and inactive. My company is using Linq, so I must follow. I wrote in this style, I calling a changeToWord() function to change 1 and 0 to active and inactive.
var q=from a in db.members
select new{
mem_name=a.name,
status=ChangeToWords(a.status)
}
It compiles with no error, but when I execute the page, it prompt out a error message to me. Thanks.
vinz
All-Star
126926 Points
17922 Posts
MVP
Re: calling function in linq query
Apr 08, 2010 12:14 PM|LINK
could you tell us what is the error you are getting?
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
aisy
0 Points
22 Posts
Re: calling function in linq query
Apr 08, 2010 12:38 PM|LINK
hey vinz,
the error msg is "Could not translate expression 'value(ASP.gui_member_List_aspx).changeToWord(a.Status)' into SQL and could not treat it as a local expression."
PeteNet
All-Star
81342 Points
11398 Posts
Re: calling function in linq query
Apr 08, 2010 02:05 PM|LINK
you could do it inline, example:
var q= from a in db.members select new { mem_name=a.name, status= a.status == 1 ? "Active" : "InActive", }if you were to call a function you could do this too:
.... statusFromFunction = ChangeStatus(a.status) ......... public string ChangeStatus(object obj) { string retVal = String.Empty; if (obj!= null) { if (obj.ToString() == "1") { retVal = "Active"; } else { retVal = "InActive"; } } return retVal; }Linq to SQL codebehind function
Peter