EF 4:指定类型的成员'*'不是在LINQ支持实体 [英] EF 4: The specified type member '*' is not supported in LINQ to Entities

查看:184
本文介绍了EF 4:指定类型的成员'*'不是在LINQ支持实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个映射类是这样的:

i have a mapped-class like this:

[Table("MyTable")]
class MyClass         
{   
        //properties; id, name, etc...

        private string _queuedToWHTime = string.Empty;
        [Column("QueuedToWHTime")]
        public string QueuedToWHTime
        {
            get { return _queuedToWHTime; }
            set { _queuedToWHTime = value; }
        }

        public DateTime? QueuedToWHTime_DateTime
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(_queuedToWHTime))
                {
                    return Convert.ToDateTime(_queuedToWHTime);
                }
                return null;
            }
        }
}

和一个表(MyTable的)

and a table (MyTable):

CREATE TABLE webnews_in
(
Id                INT NOT NULL auto_increment,
QueuedToWHTime    VARCHAR (50) NULL
...
PRIMARY KEY (Id)
);

当我尝试查询是这样的:

when i trying to query like this:

var searchRslt=(from m in queryableNews
    orderby m.QueuedToWHTime_DateTime descending
    select m).ToList();



我得到了一个引发NotSupportedException 指定的类型成员QueuedToWHTime_DateTime'不是在LINQ支持实体。只有初始化,实体成员和实体导航属性都支持。

推荐答案

您不能与EF自定义属性查询。自定义属性不能在SQL中进行翻译。

You cannot query with EF on custom properties. The custom property cannot be translated in SQL.

您可以做到这一点,强制排序依据做'内存'。

You can do this to force the orderby to be done 'in-memory'.

var searchRslt = queryableNews
    .AsEnumerable()
    .OrderBy(m => m.QueuedToWHTime_DateTime)
    .ToList();

这篇关于EF 4:指定类型的成员'*'不是在LINQ支持实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆