Addi Khan Addi Khan - 1 year ago 48
ASP.NET (C#) Question

How to solve error in LINQ: Data is null or empty

I have the following code. I want to check if the result is

with an if condition but it always shows an error. How to solve this?

string StrRefNo = Request.QueryString["ref"];
string[] SMSid = StrRefNo.Split('$');

DownloadsDbEntities db = new DownloadsDbEntities();
var data = (from d in db.SMSLink_Expiry
where d.RefNo == SMSid[0]
&& d.SMSLink.ID == Convert.ToInt32(SMSid[1])
select d).ToList();

if (data.Count > 0)
string ss = "yes";

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

Answer Source

Since the expression can not be translated into SQL, pull it out of the statement

string SMSId0 = SMSid[0];
int SMSId1 = Convert.ToInt32(SMSid[1]);

var data = (from d in db.SMSLink_Expiry
           where d.RefNo == SMSId0 
           && d.SMSLink.ID == SMSId1
           select d).ToList();