如何返回一个IQueryable<东西>作为一个IQueryable< ISomething> [英] How to return an IQueryable<Something> as an IQueryable<ISomething>

查看:180
本文介绍了如何返回一个IQueryable<东西>作为一个IQueryable< ISomething>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类的东西实现 ISomething 。我如何转换/施放从的IQueryable<东西> 的IQueryable< ISomething> 。当我尝试投,我能够编译,但是中投的结果总是NULL。

I have a class Something that implements ISomething. How can I convert/cast from an IQueryable<Something> to an IQueryable<ISomething>. When I try to cast, I am able to compile, but the result of the cast is always NULL.

背景:我这样做的原因是因为我的的东西类是codeSmith生成的类(PLINQO模板),有映射表装饰,方法,等我的 ISomething 界面POCO风格,因为它是愚蠢的,只是反映了东西的属性类。它也存在于它自己的命名空间。我这样做,所以我不必引用持有的东西类从我的服务层的组件。即持有东西组装类只需要在我的仓库层被引用了。

Background: The reason I am doing this is because my Something class is a CodeSmith-generated class (PLINQO template) that has table mapping decoration, methods, etc. My ISomething interface is "POCO-style", in that it is dumb and simply mirrors the properties of the Something class. It also exists in it's own namespace. I am doing this so I don't have to reference the assembly that holds the Something class from my service layer. The assembly that holds the Something class will only need to be referenced in my repository layer now.

推荐答案

您可以使用LINQ方法Cast

You can use LINQ method Cast

 IQueryable<Something> something = ...
 IQueryable<ISomething> casted = something.Cast<ISomething>();

这篇关于如何返回一个IQueryable&LT;东西&GT;作为一个IQueryable&LT; ISomething&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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