我正在尝试在一个MVC项目中加入两个不同的类模型,所以我可以命令它们上升/下降.我已经尝试了几种排列,但似乎无法让LINQ查询发挥得很好.关于我做错的任何建议?
var lateContact = from c in jplatestContact join s in JPStudent on c.ApplicationUserId equals s.ApplicationUserId orderby c.jplatestContactDate ascending select s;
我是初学者,但如果我理解正确,“c”和“s”是我自己组成的变量. “jplatestContact”和“JPStudent”是我想要加入的两个模型/类/表,并且都有“ApplicationUserId”我可以加入它们,我想通过在“jplatestContactDate”中找到的值来命令所有结果jplatestContact模型,按升序排列.
根据我上面写的查询,我得到一个CS0119错误“’jplatestContact’是一个类型,在给定的上下文中无效.”
我不确定我的结构在哪里出错,或者我在某种程度上误用了JOIN结构?
解决方法
您不能在类型上运行LINQ选择,只能在该类型的集合上运行 – 即任何实现IEnumerable< jplatestContact>的集合.或者IQueryable< jplatestContact>,例如List< jplatestContact>,dbContext.jplatestContact等.对于JPStudent也是如此 – 你需要一个集合或IQueryable< JPStudent>为了它.
var lateContact = from c in dbContext.jplatestContact join s in dbContext.JPStudent on c.ApplicationUserId equals s.ApplicationUserId orderby c.jplatestContactDate ascending select s;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。