Skip to content

Instantly share code, notes, and snippets.

@sapiens
Last active January 12, 2016 21:24
Show Gist options
  • Save sapiens/789c5068f63880dbc95e to your computer and use it in GitHub Desktop.
Save sapiens/789c5068f63880dbc95e to your computer and use it in GitHub Desktop.
SqlFu3 in action
//selecting related assets from a view then processing each row
//into a RelatedItem which gets added to a result
//generated sql is
//select [Id],[Type],[Name],[ContextId] from [AssetUsagesView]
//where ((([AssetId] = @0) and ([ProjectId] = @1)) and [Category] in (@3,@4))
using (var db = await _db.CreateAsync(cancel))
{
await db.QueryAndProcessAsync(
q =>
q.From<AssetUsagesViewRow>()
.Where(d=>d.AssetId==input.AssetId && d.ProjectId==input.ProjectId.Value
&& new[] {LinkCategory.CmdTriggers.ToString(),LinkCategory.TriggerEvents.ToString()}.Contains(d.Category))
.Select(d=>new AssetBasicInfo())
, a =>
{
rez.Add(new RelatedItem(a));
return true;
},cancel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment