不能隱式轉換類型'short?'以'短'在LocalAmount = t.EmpNo。我用但隨後'join'
子句將得到一個錯誤,並"incorrect", "type inference failed..."
LINQ:不能將short轉換爲short嗎?
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」 – Rex
在你的數據庫後端,是什麼想必'EmployeeAccesses.EmpNo'不明確'NOT NULL'。考慮將'public Int16 LocalAmount'改爲'public Int16? LocalAmount'。 – jdphenix
您使用的是LINQ到SQL還是EF?哪個.NET版本? – jdphenix