Created
March 14, 2011 00:41
-
-
Save felipeleusin/868603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This works | |
public class Users_ContractCharges : AbstractIndexCreationTask | |
{ | |
public override IndexDefinition CreateIndexDefinition() | |
{ | |
return new IndexDefinition<User, User>() | |
{ | |
Map = results => from user in results select new { user.Id }, | |
TransformResults = (database, results) => from user in results | |
from charges in user.Contract.Charges | |
select new | |
{ | |
charges.Name, charges.Type, charges.Value | |
} | |
} | |
.ToIndexDefinition(DocumentStore.Conventions); | |
} | |
} | |
// This doesnt, but IMO, should work | |
public class Users_ContractCharges2 : AbstractIndexCreationTask | |
{ | |
public override IndexDefinition CreateIndexDefinition() | |
{ | |
return new IndexDefinition<User, User.UserContract.SalaryCharge>() | |
{ | |
Map = results => from user in results | |
from charges in user.Contract.Charges | |
select new | |
{ | |
charges.Name, | |
charges.Type, | |
charges.Value | |
}, | |
Reduce = results => from charges in results | |
group charges by new { charges.Name, charges.Type } into g | |
select new { Name = g.Key.Name, Type = g.Key.Type, Value = g.Max(x => x.Value)}, | |
} | |
.ToIndexDefinition(DocumentStore.Conventions); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment