zoukankan      html  css  js  c++  java
  • Linq之select不能返回其类型的解决方案

     public IEnumerable<ChildCate> GetChildCates()
            {
                var dc=new Models.DbContext();
                var s = from t in dc.GetTable<ChildCate>()
                        where t.ParentID == ID
                        orderby t.ID descending
                        select new { t.Tag, t.Name, table = t };
                return s; 
       }
    上面会报错吧
    解决方案新建一个实体类
    public class Category
        {
            public int ID { get; set; }
            public string Tag { get; set; }
            public string Name { get; set; }
        }
    然后将第一段的代码改为:

            public IEnumerable<Category> GetChildCates()
            {
                var dc=new Models.DbContext();
                var s = from t in dc.GetTable<ChildCate>()
                        where t.ParentID == ID
                        orderby t.ID descending
                        select new Category{Tag=t.Tag,Name=t.Name,ID=t.ID};
                return s;
            }

    大功告成:
    支持小第网站:http://www.cnyolee.com
  • 相关阅读:
    python中的面向对象编程
    python global vs nonlocal (2)
    python3 nonlocal vs global
    poj蚂蚁问题
    C/C++ static vs global
    砝码问题
    Wythoff's game
    C++中的::operator new, ::operator delete
    客户信息表 自我汇总 待确认
    Oracle Savepoint
  • 原文地址:https://www.cnblogs.com/newmin/p/1546379.html
Copyright © 2011-2022 走看看