开发者

LINQ "table" variable

开发者 https://www.devze.com 2022-12-08 07:45 出处:网络
I\'m trying to turn a method I have right now into a more \"generic\" method that returns a string.Right now, the method uses a statement like this:

I'm trying to turn a method I have right now into a more "generic" method that returns a string. Right now, the method uses a statement like this:

var app = (from d in testContext.DAPPs
     where d.sserID == (Guid)user.ProviderUserKey
     select d).ToList();

I process the results of "app", add extra text etc. The piece that changes (that I need to make m开发者_JS百科ore "generic") is the table name (DAPPs). Is there a way I can do that, or, a better way to go around this all together?


You'll have to compose a Dynamic Linq Query.

There are a couple of ways to do this. Have a look at the following:

Dynamic Expressions in Linq to Sql
http://www.west-wind.com/Weblog/posts/143814.aspx

Using the LINQ Dynamic Query Library
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消