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
  • 相关阅读:
    正则判断是否为纯数值
    前后端加密解密crypto.js
    小程序使用iconfont字体图标
    LeetCode-Combination Sum II
    LeetCode-Combination Sum
    Google 2013 campus test-R1
    Google Codejam
    LeetCode-Count and Say
    LeetCode-Binary Tree Level Order Traversal II
    LeetCode-Binary Tree Level Order Traversal
  • 原文地址:https://www.cnblogs.com/newmin/p/1546379.html
Copyright © 2011-2022 走看看