I have a string
parameter which that i want to compare with int
and string
in Linq query
.
var query=(from GRD in _tblMembers.GetQueryable()
select new MembersModel
{
SchoolID = GRD.SchoolID,
MemberID = GRD.MemberID,
MemberReferenceID = GRD.MemberReferenceID,
MemberTypeID = GRD.MemberTypeID,
MemberNo = GRD.MemberNo,
MemberName = GRD.MemberName,
CellNo = GRD.CellNo,
}).Where(z => z.MemberName.Contains(param.sSearch) || z.MemberTypeID.Contains(param.sSearch)).ToString();
when i tried to convert database parameter to to string type using ToString()
method as follows.
.Where(z => z.MemberName.Contains(param.sSearch) || z.MemberTypeID.ToString().Contains(param.sSearch)).ToString();
linq throw run time exception.
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
How can i do coversion in linq query.
You can use SqlFunctions.StringConvert
.Where(z => z.MemberName.Contains(param.sSearch)
|| SqlFunctions.StringConvert((double)z.MemberTypeID).Contains(param.sSearch))
.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With