下面是該Application Entity
:System.InvalidCastException發生在EntityFramework.Core.dll
public class Application
{
[Key]
[Column(TypeName = "integer")]
public int ApplicationID { get; set; }
[Required]
[Column(TypeName = "nvarchar(50)")]
public string ApplicationName { get; set; }
[Column(TypeName = "nvarchar(150)")]
public string Description { get; set; }
[Required]
[ForeignKey("mTechnology")]
[Column(TypeName = "integer")]
public int TechnologyID { get; set; }
[Required]
[Column(TypeName = "int")]
public string CreatedBy { get; set; }
[Required]
[Column(TypeName = "datetime")]
public DateTime CreatedDate { get; set; }
public virtual mTechnology Technology { get; set; }
}
上執行以下LINQ查詢,我在foreach loop
List<int> technologyList = new List<int>();
var query = from a in _mApplicationDbContext.Applications
group a.Technology by a.TechnologyID into g
select new
{
TechnologyID = g.Key
};
foreach (var item in query)
{
technologyList.Add(item.TechnologyID);
}
在
run-time
得到一個錯誤
以下是錯誤信息:
類型'System.In的異常validCastException」發生於 EntityFramework.Core.dll但在用戶代碼中沒有處理
其他信息:無法轉換類型的對象‘System.Int32’ 爲類型‘System.String’。
是LINQ查詢錯誤還是其他錯誤?
謝謝!爲解決方案和旁註。 –