1

In a C# 2008 windows application, I have the following linq to sql statement that points to a sql server 2008 r2 database. The following query returns null. But there are records to be fetched.

//Code

   string SubmissionPkgID = "valid string value";
   var varGoodTransCount = (from t in rData.Transactions
   join iw in rData.Ibooks on t.ImportID equals iw.ImportID
   join ip in rData.IPackages on iw.PID equals ip.PID
   where (ip.trc_num != null) && ip.trc_num == SubmissionPkgID
   group ip by ip.trc_num into g
   select new { trc_num = g.Key, Frequency = g.Count() }).FirstOrDefault();

Note: SubmissionPkgID does contain a valid value. Where i'm worng?

2

1 Answer 1

1

Your linq query look ok it must work. rData.IPackages.trc_num is int or mumeric right? so you may use HasValue instead of checking Null value.

//Code

string SubmissionPkgID = "valid string value";
var varGoodTransCount = (from t in rData.Transactions
                        join iw in rData.Ibooks on t.ImportID equals iw.ImportID
                        join ip in rData.IPackages on iw.PID equals ip.PID
                        where (ip.trc_num.HasValue)  && ip.trc_num == SubmissionPkgID
                        group ip by ip.trc_num into g
                        select new { trc_num = g.Key, Frequency = g.Count() })
   .FirstOrDefault();

Hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.