Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC 3中的MySQL:不支持指定的方法_C#_Asp.net Mvc_Asp.net Mvc 3_Linq_Mysql Connector - Fatal编程技术网

C# MVC 3中的MySQL:不支持指定的方法

C# MVC 3中的MySQL:不支持指定的方法,c#,asp.net-mvc,asp.net-mvc-3,linq,mysql-connector,C#,Asp.net Mvc,Asp.net Mvc 3,Linq,Mysql Connector,在我的MVC3项目中,我使用的是MySQL连接器。当我试图调用该方法时,我得到了指定的方法不受支持的错误。为什么? public IList<Order> GetOrders() { return (from x in db.Order where (x.Address.FirstOrDefault() != null) orderby x.Created //it's a DateT

在我的MVC3项目中,我使用的是MySQL连接器。当我试图调用该方法时,我得到了
指定的方法不受支持的错误。为什么?

    public IList<Order> GetOrders()
    {
        return (from x in db.Order 
                where (x.Address.FirstOrDefault() != null) 
                orderby x.Created //it's a DateTime
                descending select x).ToList(); 
    }

对于某些ORM工具,并非所有LINQ方法都是现成支持的。我知道我在过去使用过NHibernate。为了实现这一点,您必须重写您的逻辑以使用更传统的方法。试试这个:

return (from x in db.Order 
            where x.Address.Count() > 0 
            orderby x.Created //it's a DateTime
            descending select x).ToList();
或者,如果出于某种原因您不喜欢上述内容,您的另一种选择是首先通过解析将集合放入内存中,然后执行您的逻辑(但请记住,这将较慢,因为它将从数据库带回更多数据):


看起来很有趣,我去查一下。我自己也找到了工作代码。谢谢
return (from x in db.Order 
            where x.Address.Count() > 0 
            orderby x.Created //it's a DateTime
            descending select x).ToList();
return (from x in db.Order
            orderby x.Created //it's a DateTime
            descending select x)
       .ToList() //resolve the query, now work with it in memory from here
       .Where(x => x.Address.FirstOrDefault() != null)
       .ToList();