Mapper entities without foreign key
See original GitHub issue@acjh Good morning, I am working with the AuditLog entity. I want to implement a service that returns all the logs that have been generated, and that these come with the user who performed the action. When I use the repository with the GetAllInclude method I cannot link the user because it is not the entity’s foreign key. How can I return the mapped object with user information? I want to replace GetAll by GetAllInclude. My code
Service:
public async Task<PagedResultDto<AuditLogDto>> GetAllAudityLog(PagedAuditLogResultRequestDto input)
{
var query = _auditLogRepository.GetAll()
.WhereIf(input.UserId > 0, t => t.UserId == input.UserId)
.Take(input.MaxResultCount)
.Skip(input.SkipCount);
var auditLogs = await query.ToListAsync();
return new PagedResultDto<AuditLogDto>
{
TotalCount = auditLogs.Count,
Items = ObjectMapper.Map<List<AuditLogDto>>(auditLogs)
};
}
DTO:
[AutoMapFrom(typeof(AuditLog))]
public class AuditLogDto : EntityDto<long>
{
public DateTime ExecutionTime { get; set; }
public string Exception { get; set; }
public string BrowserInfo { get; set; }
public string ClientName { get; set; }
public string ClientIpAddress { get; set; }
public int ExecutionDuration { get; set; }
public string ReturnValue { get; set; }
public string MethodName { get; set; }
public string ServiceName { get; set; }
public long? UserId { get; set; }
public string Parameters { get; set; }
public string CustomData { get; set; }
// How fill this field in mapper
public UserDto User { get; set; }
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to make Many-to-one mapping without foreign key in ...
1 Answer. Keyless entities (entity without key) cannot be principal of a relationship, because there is no key to be referenced by the...
Read more >Relationships, navigation properties, and foreign keys - EF6
A foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data...
Read more >Map one object to another object without using foreign key
hi, is there any solution to map one object into another object without using foreign key? for example, something like bellow: @Entity ......
Read more >What's the deal with mapping foreign keys using the Entity ...
Mapping foreign keys is not a good idea from a purist's point of view because it results in storage concerns leaking into the...
Read more >Designing for Related Data without Foreign Keys | Blog
Foreign Keys without the constraints. You don't have to configure a foreign key constraint on a column just because it refers to another...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can check
Queryable.Join
(System.Linq
) as @acjh mentioned. There are similar examples in there.