如何使用反射构建具有动态表和列名称的 Subsonic 3 查询
我想使用代码构建动态 Subsonic 3 查询来获取类型的集合。 SQL 会像这样:
select * from @tableName where @columnName1 = @columnValue1
亚音速查询看起来像这样:
List<object> = new DB.Select.From<getTypeClass(tableName)>.Where(columnName1).IsEqualTo(columnValue1).ExecuteTypeList<getTypeClass(tableName)>();
我想使用反射来完成此操作,但我认为不可能在 <> 之间放置一个非静态项。条款。
I would like to construct a dynamic Subsonic 3 query using code to get a collection of a type. The SQL would like this:
select * from @tableName where @columnName1 = @columnValue1
The subsonic query would look like this:
List<object> = new DB.Select.From<getTypeClass(tableName)>.Where(columnName1).IsEqualTo(columnValue1).ExecuteTypeList<getTypeClass(tableName)>();
I would like to accomplish this using reflection but I don't think it would be possible to put a non static item between the <> clauses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是为 Select 类上的方法生成通用方法,并能够启动相同类型的通用列表。
并像这样调用此方法:
From 方法有一个接受字符串值的重载。传递类型名称效果很好,在我的例子中,表和类名称是相同的。
在调用泛型方法之前添加一些 where 语句很容易。
The solution is to generate generic methods for the methods on the Select class and to be able to initiate a generic list of the same type.
And invoke this method like this:
The From method has an overload that accepts a string value. Passing the type name worked fine, in my case the table and class name were identical.
It is easy to add some where statements just before invoking the generic method.