下面是该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查询错误还是其他错误?
谢谢!为解决方案和旁注。 –