在LINQ中动态选择表 [英] Dynamically selecting a table in LINQ

查看:85
本文介绍了在LINQ中动态选择表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个奇怪的概括情况.在LINQ中可以动态设置表名吗?

我有一个下拉列表,指示要查询的表.

如果selectedValue == ItemA
查询表A
其他
查询表B

现在,该tableB还不存在,将在以后添加,但其结构将与tableA完全相似.目前,我们的DAL是使用LINQ实现的.是否可以在LINQ中处理这种情况?

在研发中,我找到了SQLMetal.我可以通过外部映射文件使用它吗?

问候

Hi All

I have a weird scenario of generalization. Is it possible in LINQ to set the table name on the fly ?

I have a dropdown that dictates which table to query.

If selectedValue == ItemA
Query tableA
else
Query tableB

Now this tableB is not there yet and will be added later on but its structure will be exactly similar to tableA. Currently our DAL is implemented using LINQ. Is it possible to handle this scenario in LINQ ?

In my R&D I''ve found SQLMetal. Can I use it using external mapping files ?

Regards

推荐答案

hi,
检查下面的这些链接
http://geekswithblogs.net/SudheersBlog/archive/2008/11/25/127380.aspx [ ^ ]
http://social.msdn.microsoft.com /forums/zh-CN/linqprojectgeneral/thread/6273d072-f500-4382-afb4-8eafd185794d/ [ http://blogs.msdn.com/b/marcinon/archive/2010/01/14/building-custom-linq-expressions-made-easy-with-dynamicqueryable_2e00_.aspx [

Check these links below
http://geekswithblogs.net/SudheersBlog/archive/2008/11/25/127380.aspx[^]
http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/6273d072-f500-4382-afb4-8eafd185794d/[^]

also you can try DynamicQueryable feature of LINQ
http://blogs.msdn.com/b/marcinon/archive/2010/01/14/building-custom-linq-expressions-made-easy-with-dynamicqueryable_2e00_.aspx[^]

Hope this will help.


我怀疑,像任何代码生成任务一样,您需要使用反射来做到这一点.
I suspect that, like any code generation task, you''d need to use reflection to do this.


这篇关于在LINQ中动态选择表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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