私は以下のようなクラスを持っています
public class GrouppedStockGift
{
public DateTime? TimeCreated { get; set; }
public int? StoreID { get; set; }
public int? UserCreated { get; set; }
public int? WorksID { get; set; }
public int? WorkOrderCode { get; set; }
public decimal? GiftPrice { get; set; }
public decimal? GiftMoney { get; set; }
public int SaleCount { get; set; }
}
動的式ビルダーを作成しました。場合によっては、intconvert int? to int
またはgetdefaultvalue
int が必要な場合があります
var sumMethodint = typeof(Enumerable).GetMethods()
.Single(x => x.Name == "Sum"
&& x.GetParameters().Count() == 2
&& x.GetParameters()[1]
.ParameterType
.GetGenericArguments()[1] == typeof(int?));
sumMethodint = sumMethodint.MakeGenericMethod(typeof(GrouppedStockGift));
Expression<Func<GrouppedStockGift, int?>> SaleCount = y => y.SaleCount;
var SaleCountExtractor = Expression.Call(sumMethodint, parameter, SaleCount);
bindings.Add(
Expression.Bind(
typeof(GrouppedStockGift).GetProperty("SaleCount"),
SaleCountExtractor));
しかし、最後の行を実行すると、型が一致していないため例外が返されますSaleCount
が、合計メソッドは int を返しますか?
誰でも私を助けることができますか?