Linq to Entities将表名称传递给函数 [英] Linq to Entities Pass Table name to function

查看:107
本文介绍了Linq to Entities将表名称传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF项目中使用Linq to Entities.按照逻辑,我需要从UI中动态选择表名.这意味着,我需要将表名传递给Function并使用它.

代码如下:::

公共列表<  记录 >  GetNonDuplicateRecords()
          {

              ThreeEntities threeentities =新ThreeEntities();

              List <  记录 >  recs = (来自Threeentities中的p.UE_Aetna

                                    选择新记录
                                    {
                                        _claimNumber = p.ClaimNumber,
                                        _firstname = p.PatientFirstName,
                                        _lastname = p.PatientLastName,
                                        _client = p.Client
                                    }).ToList <  记录 > ();

              返回记录
          } 



代替上面没有参数的函数GetNonDuplicateRecords(),我将传递GetDuplicateRecords(string TableName),然后在Linq查询中使用它,如下所示.


公共列表<  记录 >  GetNonDuplicateRecords(string tableName)
          {

              ThreeEntities threeentities =新ThreeEntities();

              List <  记录 >  recs = (来自Threeentity中的p, .TableName 应使用此"

                                    选择新记录
                                    {
                                        _claimNumber = p.ClaimNumber,
                                        _firstname = p.PatientFirstName,
                                        _lastname = p.PatientLastName,
                                        _client = p.Client
                                    }).ToList <  记录 > ();

              返回记录
          } 



Linq to Entities中是否有此可能性.

提前谢谢.

chowdary.

解决方案

您是否看过:
用于LINQ-to-SQL的动态表映射

I am using Linq to Entities in my WPF project. As per the logic i need to select table name dynamically from the UI. this means, I need to pass Table name to the Function and using this.

Code as follows.::

public List<Records> GetNonDuplicateRecords()
          {

              ThreeEntities threeentities = new ThreeEntities();

              List<Records> recs = (from p in threeentities.UE_Aetna

                                    select new Records
                                    {
                                        _claimNumber = p.ClaimNumber,
                                        _firstname = p.PatientFirstName,
                                        _lastname = p.PatientLastName,
                                        _client = p.Client
                                    }).ToList<Records>();

              return recs;
          }



Instead of above function GetNonDuplicateRecords() with no arguments i will pass GetDuplicateRecords(string TableName) then in Linq query it should use as following.


public List<Records> GetNonDuplicateRecords(string tableName)
          {

              ThreeEntities threeentities = new ThreeEntities();

              List<Records> recs = (from p in threeentities.TableName "Should use this"

                                    select new Records
                                    {
                                        _claimNumber = p.ClaimNumber,
                                        _firstname = p.PatientFirstName,
                                        _lastname = p.PatientLastName,
                                        _client = p.Client
                                    }).ToList<Records>();

              return recs;
          }



Is there any possibility for this in Linq to Entities.

Thanks in advance.

chowdary.

解决方案

have you looked at :
Dynamic Table Mapping for LINQ-to-SQL


这篇关于Linq to Entities将表名称传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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