0

Problem: I have to check whether or not a record exists in a join and if not ignore that user but still load all the other information for that user

var db = Simple.Data.Database.OpenNamedConnection("sqlConn");  
02   
03 var expr1 = db.PON_APP_USERS.STATUS == 1;  
04   
05 var sUsers = db.PON_APP_USERS.FindAll(expr1)  
06 .Select(  
07     db.PON_APP_USERS.USERKEY,  
08     db.PON_APP_USERS.LAST_NAME,  
09     db.PON_APP_USERS.FIRST_NAME,  
10     db.PON_APP_USERS.AGENCY,  
11     db.PON_APP_USERS.USERUSERS.CBI_NO,  
12     db.PON_APP_USERS.USERUSERS.EXPRNC_STAT_IN,  
13     db.PON_APP_USERS.USERUSERS.TEST_STAT_IN,  
14     db.PON_APP_USERS.USERUSERS.TWO_WKS_TRNG_DT)  
15 .LeftJoin(db.USERUSERS, USERKEY: db.PON_APP_USERS.USERKEY); 

I'm new to simple data as in, 2 days new. So if you don't mind showing me step by step it would be greatly appreciated. This is what they are requesting of that join:

/// If no record is join with the above statement, page will crash. Please make adjustments to allow the page to load if the user does not have a record in USERUSERS table.

Brandon
  • 645
  • 5
  • 13
ghostfly
  • 3
  • 3
  • Why don't you just use an IF statement? Say IF whatever criteria is null then load the rest. Or count the records it returns base if off that. – Kpt.Khaos Apr 25 '14 at 15:30
  • There is nothing in that code that will cause an error in Simple.Data itself. It may be that you are trying to access one of the values from the `USERUSERS` table without first checking to see if it is null? – Mark Rendle Apr 25 '14 at 16:27
  • thanks mark-- I had forgot to include a null check for userkey – ghostfly Apr 25 '14 at 18:06

0 Answers0