Created
September 15, 2012 14:28
-
-
Save davybrion/3728197 to your computer and use it in GitHub Desktop.
code snippets for "Think Twice Before You Map Entities To DTOs" post
This file contains hidden or 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
public class AuthorizationDto | |
{ | |
public long Id { get; set; } | |
public Guid ApplicationId { get; set; } | |
public string ApplicationName { get; set; } | |
public Guid? UserGroupId { get; set; } | |
public string UserGroupName { get; set; } | |
public Guid? UserId { get; set; } | |
public string Username { get; set; } | |
public Guid PermissionId { get; set; } | |
public string PermissionName { get; set; } | |
public string PermissionDescription { get; set; } | |
} |
This file contains hidden or 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
var items = Session.CreateCriteria<Authorization>() | |
.CreateAlias("Application", "a", JoinType.InnerJoin) | |
.CreateAlias("User", "u", JoinType.LeftOuterJoin) | |
.CreateAlias("UserGroup", "g", JoinType.LeftOuterJoin) | |
.CreateAlias("Permission", "p", JoinType.InnerJoin) | |
.Future<Authorization>(); | |
var dtos = new AuthorizationDtoMapper().ToDtos(items); |
This file contains hidden or 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
var dtos = Session.CreateCriteria<Authorization>() | |
.CreateAlias("Application", "a", JoinType.InnerJoin) | |
.CreateAlias("User", "u", JoinType.LeftOuterJoin) | |
.CreateAlias("UserGroup", "g", JoinType.LeftOuterJoin) | |
.CreateAlias("Permission", "p", JoinType.InnerJoin) | |
.SetProjection(Projections.ProjectionList() | |
.Add(Projections.Id(), "Id") | |
.Add(Projections.Property("a.Id"), "ApplicationId") | |
.Add(Projections.Property("a.Name"), "ApplicationName") | |
.Add(Projections.Property("u.Id"), "UserId") | |
.Add(Projections.Property("u.UserName"), "Username") | |
.Add(Projections.Property("g.Id"), "UserGroupId") | |
.Add(Projections.Property("g.Name"), "UserGroupName") | |
.Add(Projections.Property("p.Id"), "PermissionId") | |
.Add(Projections.Property("p.Name"), "PermissionName") | |
.Add(Projections.Property("p.Description"), "PermissionDescription")) | |
.SetResultTransformer(new AliasToBeanResultTransformer(typeof(AuthorizationDto))) | |
.Future<AuthorizationDto>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment