Not able map joined entities into main model
See original GitHub issueLinq2 DB not mapped child entities on custom dto entities
I not find in documentation how do it, but I want auto map from my sql query with join entities this child entities to list, but have only mapped main entity like in plain sql use.
Note: I not use assotions for it becouse in my case I have one generic field for many other entities.
public class StoreVm
{
public StoreVm()
{
Documents = new List<DocumentVm>();
}
public long CardId { get; set; }
public string Title { get; set; }
public StoreType Type { get; set; }
public long Id { get; set; }
public DateTimeOffset CreatedOn { get; set; }
public List<DocumentVm> Documents { get; set; }
}
public class DocumentVm
{
public long Id { get; set; }
public string Name { get; set; }
public string Path { get; set; }
}
var sqlQuery = new StringBuilder($"SELECT \"Store\".\"CardFK\" AS \"CardId\", \"Store\".\"CreatedOn\", \"Store\".\"Title\", \"Store\".\"Type\", \"Store\".\"DeletedOn\", \"Store\".\"Id\",\r\n\t\"Document\".\"Id\", \"Document\".\"Name\", \"Document\".\"Path\" FROM public.\"Store\" JOIN public.\"Document\" ON \"Store\".\"Id\" = \"Document\".\"RecordId\" WHERE \"Document\".\"RecordType\" = 1 AND \"Store\".\"CardFK\" = 35");
var resQuery = DbConnection.FromSql<StoreVm>(sqlQuery.ToString()).ToArray(); //not mapped documents vm
Environment details
Linq To DB
version: 4.3.0
Database (with version): PostrgeSQL 14
Operating system: Windows
.NET (Core): 6
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Unable to map collection in onetomany mapping JPA
Look at your mapping. You are trying to map a FK in the element table. @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "item_id", ...
Read more >Advanced table mapping - EF Core
EF Core allows to map two or more entities to a single row. ... between the primary key of one entity type and...
Read more >Chapter 2. Mapping Entities
If the property is of a single type, it is mapped as @Basic. Otherwise, if the type of the property is annotated as...
Read more >Automatically Mapping DTO to Entity on Spring Boot APIs
Let's learn how ModelMapper can help us automate the mapping process of DTOs into entities on Spring Boot APIs.
Read more >Hibernate Tips: How to map a bidirectional many-to- ...
Solution: You need to model the association on both entities if you want to be able to navigate it in both directions. Let's...
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 Free
Top 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
Actually not planned because
linq2db
is more LINQ oriented, but for sure it can be implemented if we design useful API for that. Check how it works in Dapper https://www.learndapper.com/relationships - my thoughts: LINQ is better.@sdanyliv So thanks will know. Does it planned on feature(collection properties mapping)?