Cast Nullable Ints inside your Select in Linq

Needed to return a single value and cast it as an int instead of an int?

    public int getFranchiseePOS(string AccountCode)
        {
            var qry = (from s in MyEntities.Franchisees
                       join p in MyEntities.POS on s.POSID equals p.POSID into XX
                       from subgroup in XX.DefaultIfEmpty()
                       where s.AccountCode == AccountCode
                       select s.POSID==null ? 0 :(int) s.POSID

                      ).FirstOrDefault();

            return qry;
        }

Comments

Popular posts from this blog

Linq Exclude from separate list

Sorting Ascending and Descending

Linq Query Syntax vs Method Syntax