我有这个错误不能隐式地将Enumerable行集合<short>
转换为这行代码中的short:
Month = (from item in query select (short)item.Month);
我想知道为什么以及为什么我在查询变量中找不到distinct()或count方法。
这是我的方法:
public bool IsEnableAccPosting(
string CompanyCode, DateTime FromDate, DateTime ToDate, out short Month)
{
try
{
o_dmDebitAccounts = new dmDebitAccounts(sysInfo);
bool IsEnable = false;
DataTable dt = o_dmDebitAccounts.GetDebitInterestAccPeriods(CompanyCode);
var query = from data in dt.AsEnumerable()
where data.Field<DateTime>("StartDate") == FromDate &&
data.Field<DateTime>("EndDate") == ToDate
select new
{
Month = Convert.ToInt16(data.Field<short>("Month")),
Year = Convert.ToInt16(data.Field<short>("Year"))
};
Month = (from item in query select (short)item.Month); //heres the error
答案 0 :(得分:0)
该字段已在执行操作的linq查询中键入为Int16。你不需要施展它。
尝试以下代码taken from here
if (query.Any())
{
var result = query.First();
// Console.WriteLine("Results: {0}", result.Month);
Month = result.Month;
}