Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am working on a console application where I have to query a table but can't run 2 query to get result set based on where clause. 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.

What I have tried:

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
C#
userStatus = (await connection.QueryAsync<userstatusobject>)).Tolist().

if (userStatus?.Any()?? false)
    foreach (var res in userStatus)
        yield return res

in the userstatus we have some thing like this
C#
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
C#
(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 vice-versa
Posted
Updated 5-Jan-22 2:50am
v2
Comments
BillWoodruff 5-Jan-22 7:41am    
fyi: there is a Dapper area on StackOverFlow: https://stackoverflow.com/search?q=dapper
[no name] 5-Jan-22 12:05pm    
If you ultimately want one variable pointing to either paiduserinfo or debtuserstatus, then you need to define an interface for the "paid" and "debt" classes and use that (e.g. IUserInfo).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900