Linq to SQL动态查询自定义表,其结构在运行时已修改 [英] Linq to SQL Dynamic query on a custom table whose structure was modified at runtime

查看:91
本文介绍了Linq to SQL动态查询自定义表,其结构在运行时已修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将使用ADO.Net的现有应用程序与Linq2SQL迁移到.Net 4+.问题在于应用程序的数据库包含一个在运行时使用GUI设计器自定义的表,即该表最初包含主键(Id)和其他3个列,但随后用户设计了将在应用程序中跟踪的数据使用GUI设计器,该设计器反过来修改此表的结构,并添加列以适应需要.设计人员还将该表的结构记录在描述这些自定义列的元数据表中.

I am migrating an existing application that uses ADO.Net to .Net 4+ with Linq2SQL. The problem is that the application's database contains a table that is customized at runtime using a GUI designer, i.e. the table initially contains the primary key (Id) and 3 other columns, but then the user designs the data that will be tracked in the application using a GUI designer which in turn modifies the structure of this table adding the columns to accommodate the need. The designer also records the structure of this table in a meta-data table that describes these custom columns.

当前应用程序将构建SQL字符串以构建查询.如何使用Linq2SQL处理该表的查询?使用context.ExecuteQuery<>是唯一的方法吗?

The current application builds SQL strings to build queries. How can I handle querying from this table using Linq2SQL? Is using context.ExecuteQuery<> the only way to do it?

推荐答案

我相信您可以使用dynamic.cs来获取所需的内容.最好使用存储过程,并在存储过程中完成动态sql.这是带有示例的dynamic.cs链接.

I believe you can use dynamic.cs to get what you are looking for. Might be better to use stored procedures and have the dynamic sql done in the sprocs. Here is the link to dynamic.cs with examples.

dynamic.cs

这篇关于Linq to SQL动态查询自定义表,其结构在运行时已修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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