nithya shiva

nithya shiva

  • NA
  • 15
  • 1.3k

how to make separate object based on sql query output?

Jan 5 2022 12:05 PM

HI i am working on a console application where i have to query a table but cant run 2 query to get result set based on where clasue. its a internal restriction. lets say i have a table which has a column header caller status and the default entries in it are paid or debt. 

I am working on a entity framework project where i am using dapper to map the sql output to map it into a c# object. 

this is my code for mapping the sql query to a default object


    userStatus = (await connection.QueryAsync<userStatusObject>)).Tolist().
    
    if (userStatus?.Any()?? false)
        forwach (var res in userStatus)
        yield return res
    
in the userstatus we have some thing like this 

public class userStatusObject 
{
    public string name {get; set;}
    public int id {get; set;}
    public string status {get; set;}
    
}

here the status may be paid or debt 

now i need to pass the res based on status into two different object
 
 
 the code is like this 
 
 
  (for result in userstatus)
  {
     var paiduserstatus  = new paiduserinfo()// paid userinfor is a seperate object 
        {
           name = result.name,
           id = result.id,
           status = result.status,
           data = xxxxxxxx
        }

    var debtuserstatus  = new debtuserinfo()// debt userinfor is a seperate object 
        {
           name = result.name,
           id = result.id,
           status = result.status,
           data = xxxxxxxx
        }        
  }
  

So what i am trying to do is run the query and and if the status is paid i need it to pass status as paid in paid user and no should not call debtuserstatus and same as viseversa


Answers (1)