سؤال

Is there a way to build the Select statement in parts? I am building a dynamic query by working through loops, which works well for the FROM / JOIN aspects, but can't make the Select work...

e.g. rather than this:

var results = query.Select(
    u1.FirstName.As("AssistantName"),
    u2.FirstName.As("LeadName")
);

something like this:

var select = new SelectBuilder();
select.Add(u1.FirstName.As("AssistantName"));
select.Add(u2.FirstName.As("LeadName"));
var results = query.Select(select);

Any guidance much appreciated!

هل كانت مفيدة؟

المحلول

You can pass an IEnumerable<SimpleReference> to the Select method, for example:

var columns = new List<SimpleReference>();
columns.Add(u1.FirstName.As("AssistantName"));
columns.Add(u2.FirstName.As("LeadName"));
var results = query.Select(columns).ToList();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top