New Posts New Posts RSS Feed: Generic Distinct Projection
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Generic Distinct Projection

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: Generic Distinct Projection
    Posted: 25-Jan-2011 at 4:29pm
Hi Calvin,
 
Sorry if it wasn't clear in my previous post, but this feature is not available yet.
 
Like I previously mentioned, the above mentioned feature (returning projections in a query built dynamically) will be available with DevForce2010 v6.0.9.0.
 
The snippets I provided are only to demonstrate what DevForce can accomplish as of now.
 
Best regards,
   Silvio.
Back to Top
CalvinC View Drop Down
Newbie
Newbie
Avatar

Joined: 10-Jan-2011
Posts: 4
Post Options Post Options   Quote CalvinC Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jan-2011 at 4:03pm
Thanks for the reply Silvio.

You're demo constructs the Where clause dynamically.  That's certainly useful; but it's not what I'm asking about.

I want to know if it's possible to construct a Select clause dynamically (an anonymous projection) and then subsequently append a Distinct clause.

I.e, is there a way to construct this line
    .Select(e => new {Name = e.FirstName, e.City})
dynamically (where FirstName and City are supplied as parameters)?

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jan-2011 at 3:35pm

Hi Calvin,

 
This is a feature that will be available with DevForce2010 v6.0.9.0. (returning projections in a query built dynamically)
 
 
Right now you can build the query dynamically, but it will return a collection of the Entity type being queried:
 
  var expr1 = PredicateBuilder.Make(typeof(Employee), "LastName"
    , FilterOperator.StartsWith
    , "D");
  var expr2 = PredicateBuilder.Make(typeof(Employee), "Country"
    , FilterOperator.IsEqualTo
    , "USA");
  var expr12 = expr1.And(expr2);
  var exprFunc = (Expression<Func<Employee, bool>>)expr12.ToLambdaExpression();
  var query = mgr.Employees.Where(exprFunc);
  var results = query.Execute(); // results is a collection of Employee
You can always query your large table and return a projection with only the desired fields:
 
var query = mgr.Employees
  .Where(e => e.LastName.StartsWith("D") && Country.Equals("USA"))
  .Select(e => new {Name = e.FirstName, e.City});
  var results = query.Execute(); // results is a collection of projection { Name, City }
 
Note that upon execution a query will always return IEnumerable<T> where T is an Entity type or a projection.
 
Silvio.
Back to Top
CalvinC View Drop Down
Newbie
Newbie
Avatar

Joined: 10-Jan-2011
Posts: 4
Post Options Post Options   Quote CalvinC Quote  Post ReplyReply Direct Link To This Post Posted: 24-Jan-2011 at 3:51pm

I have a large flat legacy table that has many columns.  I would like to write a generic method that can fetch the distinct values in any two columns:

IEnumerable<T1, T2> FetchUniqueValues<T1, T2>(

  Expression<Func<TheEntity, T1>> toTypeT1,

  Expression<Func<TheEntity, T2>> toTypeT2)

{

            //

}


Is there a clever way to accomplish this with DevForce?


Thanks!

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down