我有一个提供对象的存储过程。因此,我创建了一个可以捕获所有这些内容的类:
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; }
}
我的存储过程在SQL Server中运行良好:
EXEC [dbo].[DISPLAY_SOA_V4]
@UnitID = 1,
@Month = 11,
@Year = 2018
然后我像这样调用此存储过程:
public DisplaySoa DisplaySoa(DisplaySoaParameter model)
{
using(var db = new ApplicationDbContext())
{
int unitid = Convert.ToInt32(model.UnitID);
int month = Convert.ToInt32(model.Month);
int year = Convert.ToInt32(model.Year);
try
{
//const string query = "[dbo].[DUES_AUTO_PAYMENT] @PaymentAmount @PaymentTypeID @ORNumber @UnitID @CurrentDateTime";
const string query = "[dbo].[DISPLAY_SOA_V4] @UnitID @Month @Year";
object[] parameter =
{
new SqlParameter
{
ParameterName = "@UnitID",
Value = unitid,
Direction = ParameterDirection.Input,
//SqlDbType = SqlDbType.Int
},
new SqlParameter
{
ParameterName = "@Month",
Value = month,
Direction = ParameterDirection.Input,
//SqlDbType = SqlDbType.Int
},
new SqlParameter
{
ParameterName = "@Year",
Value = year,
Direction = ParameterDirection.Input,
//SqlDbType = SqlDbType.Int
}
};
var x = db.Database.SqlQuery<DisplaySoa>(query, parameter).FirstOrDefault();
return x;
}
catch(Exception ed)
{
return null;
}
}
}
但是我在尝试捕获中遇到此错误
“ @ Month”附近的语法不正确
但是,如果我删除“ .firstOrDefault()”,则会出现此错误:
另一个SqlParameterCollection已包含SqlParameter。
我真的需要您的帮助。谢谢。