abe545 / CodeOnlyStoredProcedures

A library for easily calling Stored Procedures in .NET using only code (no xml or gui).
MIT License
4 stars 3 forks source link

Allow the child key and parent key functions to be passed to the fluent syntax #62

Open abe545 opened 8 years ago

abe545 commented 8 years ago

Even easier: make them expressions, so they can be used directly by the row factory. Something like this:

StoredProcedure.Create("usp_GetTree")
    .WithResults<Tree, Branch>()
    .AsHierarchical<Tree>(tree => tree.Id, branch => branch.OwnerId);

This will clearly require overloads on the actual stored procedure classes, as every hierarchical relationship could need to be defined. At the very least, every type argument would require a getter for its Id (except the type that has no children, but which one is that going to be?), and for its parent Id. It might be better to add a new method that can be used to define the relationship between 2 of the result sets independently, so you could do this:

StoredProcedure.Create("usp_GetTree")
    .WithResults<Tree, Branch, Root, Leaf>()
    .WithHierarchicalMapping<Tree, Branch>(tree => tree.Id, branch => branch.OwnerId)
    .WithHierarchicalMapping<Tree, Root>(tree => tree.Id, root => root.TreeId)
    .WithHierarchicalMapping<Branch, Leaf>(branch => branch.Id, leaf => leaf.Branch)
    .AsHierarchical<Tree>();