Skip to content

Instantly share code, notes, and snippets.

@cathode
Created July 20, 2016 22:12
Show Gist options
  • Select an option

  • Save cathode/85b54b7294c97bf1c1026b802c99d987 to your computer and use it in GitHub Desktop.

Select an option

Save cathode/85b54b7294c97bf1c1026b802c99d987 to your computer and use it in GitHub Desktop.
// Query object mappings to find objects that should be active.
var active = context.Objects
.Join(context.ObjectSets
.Join(context.Databases
.Where(e => e.Environment == this.CurrentEnvironment),
set => set.DatabaseId,
database => database.DatabaseId,
(set, database) => new
{
ObjectSetId = set.ObjectSetId,
SetName = set.Name,
DatabaseId = database.DatabaseId,
//Environment = database.Environment,
DatabaseName = database.Name,
FilePath = database.FilePath,
ConnectionString = database.ConnectionString
}),
obj => obj.ObjectSetId,
dset => dset.ObjectSetId,
(obj, dset) => new
{
ObjectId = obj.ObjectId,
ObjectType = obj.ObjectType,
ObjectName = obj.ObjectName,
PrimaryKeyColumn = obj.PrimaryKeyColumn,
FilePath = dset.FilePath,
ConnectionString = dset.ConnectionString
})
.Join(context.ObjectMappings
.Where(m => this.CurrentApplications.Contains(m.ApplicationId)),
obj => obj.ObjectId,
map => map.ObjectId,
(obj, map) => new
{
ObjectId = obj.ObjectId,
ObjectType = obj.ObjectType,
ObjectName = obj.ObjectName,
PrimaryKeyColumn = obj.PrimaryKeyColumn,
FilePath = obj.FilePath,
ConnectionString = obj.ConnectionString,
ObjectAlias = map.ObjectAlias,
MappingType = map.MappingType
}).Distinct();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment