【发布时间】:2014-03-07 06:15:48
【问题描述】:
不能隐式转换类型“short”?在 LocalAmount = t.EmpNo 处“做空”。我使用了Convert.ToInt16(t.EmpNo),但随后'join' 子句将出错并成为"incorrect", "type inference failed..."
public class AccountTransaction
{
public Int16 LocalAmount { get; set; }
public String AccountNumber { get; set; }
}
public static IEnumerable<AccountTransaction> GetAllTransactions()
{
using (var context = new SQL_TA_SCOREBOARDEntities1())
{
return (from t in context.EmployeeAccesses
join acc in context.View_HCM
on t.EmpNo equals acc.EmpNo
select new AccountTransaction
{
LocalAmount = t.EmpNo,
AccountNumber = acc.EmailAddress
}).ToList();
}
}
【问题讨论】:
-
为什么不只是“在 (Int16)t.EmpNo 上等于 acc.EmpNo”
-
在您的数据库后端,大概是
EmployeeAccesses.EmpNo不是明确的NOT NULL。考虑将public Int16 LocalAmount更改为public Int16? LocalAmount。 -
您使用的是 LINQ-to-SQL 还是 EF?哪个 .NET 版本?
-
哦,好吧,对不起大家,我对 NULLABLE 问题一无所知。现在我明白了。非常感谢!