指定类型的成员XX”不支持实体LINQ。只有初始化,成员单位,和实体导航性能的支持。

The specified type member 'DeleteFlag' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

 

出现这个问题的原因是因为在linq中两个连接表创建的实体类需要吧其中的映射字段每一个都查出来,不然就会报这个错误,错误的写法如下

                var querySql = from t in _observationResultRepository.Table
                               join r in _observationRequestRepository.Table
                               on t.ObservationUID equals r.ObservationUID
                               select new RelatedLabResultInfo 
                               {
                                   ValueText=t.ValueText,
                                   ResultDate=r.ResultDate
                               };
  if (query.ClinicInfoType != null)
                {
                    querySql = querySql.Where(u => u.ClinicInfoType == query.ClinicInfoType.Value.ToString());
                }

这其中,tostringEF 不支持,需要写个中间变量赋值然后再放在EF中,

正确的写法:

                var querySql = from t in _observationResultRepository.Table
                               join r in _observationRequestRepository.Table
                               on t.ObservationUID equals r.ObservationUID
                               select new RelatedLabResultInfo 
                               {
                                   ValueText=t.ValueText,
                                   ResultDate=r.ResultDate,
                                   ClinicInfoType=r.ClinicInfoType
                               };

  if (query.ClinicInfoType != null) 
                {
                    ClinicInfoType = query.ClinicInfoType.Value.ToString();
                }

if (query.ClinicInfoType != null)
                {
                    querySql = querySql.Where(u => u.ClinicInfoType == ClinicInfoType);
                }

 

posted @ 2017-06-10 19:13  洛晨随风  阅读(830)  评论(0编辑  收藏  举报