System.NotSupportedException: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context. 在 System.Data.Entity.Core.Objects.E


有使用EntityFramework过程中,查询数据时,很可能会遇到如题的错误。最大的原因可能是你的查询条件的数据有问题:

如:

var comments = _taskInfoCommentRepository.GetAll().Where(p => p.Major.Equals(major)
&& p.CreationTime .CompareTo(beginDate) >= 0
&& p.CreationTime.CompareTo(endDate) <= 0

 

其中你是这样定义时间的:

DateTime? beginDate = null;

DateTime? endData = null;

于是你悲剧了。

解决方法一:

var comments = _taskInfoCommentRepository.GetAll().Where(p => p.Major.Equals(major)
&& p.CreationTime .CompareTo(beginDate.Value) >= 0
&& p.CreationTime.CompareTo(endDate.Value) <= 0

解决方法二:

DateTime beginDate = DateTime.Now;

DateTime endData =  DateTime.Now;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM