LinkQ Exception

Posted by Ravi on Stack Overflow See other posts from Stack Overflow or by Ravi
Published on 2010-05-20T08:25:11Z Indexed on 2010/05/20 8:30 UTC
Read the original article Hit count: 226

Filed under:
|

Hi,

I write Linq query for keep on fetching data from database. First loop table don't have record , so throwing exception. After first loop i have record in the database, my
query is working properly. Below i specified my query give some suggestion first loop(no records in table) i have to modify query or query have to change.

Ex:

 forloop(History history in historyList)
 {
 History history1 = (from p in context.History
                                    where p.TransferCode == history.TransferCode
                                    select p).First<History>()
                                    as History;    
 if(history1 == null)
 {
   SaveToDataBase(history);
 }
 else
 {
   UpdateToDataBase(history1);
 }
 }

Thinks

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#