I have a stored procedure that gives me this output in MSSql Server
So I created a class to catch this output like so:
public class OwnerInfo
{
public string UnitName { get; set; }
public string UnitOwner { get; set; }
}
public class FirstInfo
{
public string TType { get; set; }
public string TransactionType { get; set; }
public string Period_Covered { get; set; }
public double? BillAmount { get; set; }
public double? PaymentAmount { get; set; }
public double? Balance { get; set; }
}
public class SecondInfo
{
public string TType { get; set; }
public string TransactionType { get; set; }
public string Period { get; set; }
public double? BillAmount { get; set; }
public double? PaymentAmount { get; set; }
public double? Balance { get; set; }
}
public class ThirdInfo
{
public string TType { get; set; }
public string TransactionType { get; set; }
public string Period { get; set; }
public double? PaymentAmount { get; set; }
}
public class FourthInfo
{
public string TType { get; set; }
public string Particulars { get; set; }
public string PaymentDate { get; set; }
public double? PaymentAmount { get; set; }
public string ORNumber { get; set; }
}
public class DisplaySoa
{
public OwnerInfo OwnerInfo { get; set; }
public List<FirstInfo> FirstInfo { get; set; }
public List<SecondInfo> SecondInfo { get; set; }
public List<ThirdInfo> ThirdInfo { get; set; }
public List<FourthInfo> FourthInfo { get; set; }
}
public class DisplaySoaParameter
{
public int UnitID { get; set; }
public int Month { get; set; }
public int Year { get; set; }
}
And the way I get it from the database is in my controller and I call the stored procedure like so:
const string query = "[dbo].[DISPLAY_SOA_V4] @UnitID, @Month, @Year";
using(var db = new ApplicationDbContext())
{
try
{
//const string query = "[dbo].[DUES_AUTO_PAYMENT] @PaymentAmount @PaymentTypeID @ORNumber @UnitID @CurrentDateTime";
object[] parameter =
{
new SqlParameter
{
ParameterName = "@UnitID",
Value = model.UnitID,
Direction = ParameterDirection.Input,
SqlDbType = SqlDbType.Int
},
new SqlParameter
{
ParameterName = "@Month",
Value = model.Month,
Direction = ParameterDirection.Input,
SqlDbType = SqlDbType.Int
},
new SqlParameter
{
ParameterName = "@Year",
Value = model.Year,
Direction = ParameterDirection.Input,
SqlDbType = SqlDbType.Int
}
};
var x = db.Database.SqlQuery<DisplaySoa>(query, parameter).ToList();
return x;
}
catch (Exception ed)
{
return null;
}
}
but in my "x" value I get null like so:
That image is when I use .FirstOrDefault() bur if I use .ToList(), I get a count of 1 but nothing is insede i .Can you please help me with this? Thank you.
Your sp is returning multiple result sets.
var x = db.Database.SqlQuery<DisplaySoa>(query, parameter).ToList();
From this you can't handle that.
Please read this article for how to do that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.