c# – 如何在linq-to-sql中返回匿名类型
发布时间:2020-12-15 08:46:08 所属栏目:百科 来源:网络整理
导读:我有以下伪代码,但想法是返回一个泛型类 public static var getSeaOf(string user) { var periodsSettings = from p in sea where p.add_by == new Guid(user) select new { p.id,p.name }; return var; } 我在这里阅读 – How to return anonymous type fro
我有以下伪代码,但想法是返回一个泛型类
public static var getSeaOf(string user) { var periodsSettings = from p in sea where p.add_by == new Guid(user) select new { p.id,p.name }; return var; } 我在这里阅读 – How to return anonymous type from c# method that uses LINQ to SQL,这种情况的最佳解决方案是为返回类型创建一个类. 但我的问题是,如果我有数百个这样的函数,这是否意味着我需要有数百个类? 我希望有一个更通用的解决方案,谢谢你的帮助!! 版 我来看看 Silverlight – LinqToEntities – How Do I Return Anonymous Types 但我不能在select new中指定类名,就像文章一样? public static IEnumerable<retSea> getBskSeasonsOf(string user) { var periodsSettings = from p in sea where p.add_by == new Guid(user) select new retSea { p.id,p.name }; return periodsSettings; } 解决方法
这是一篇关于使用VS 2010的Generate From Usage功能在.NET中命名匿名类型的博客文章.
http://diditwith.net/2009/10/24/NamingAnonymousTypesWithGenerateFromUsage.aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |