Closed kadyrkulovr closed 8 years ago
Like this:
public class SimpleMapper : EntityMapper<Document>
{
public SimpleMapper()
{
Property(x => x.DocumentCategory)
.ColumnName("CategoryId")
.ToPropertyValue(x => new DocumentCategory { Id = (int)x });
}
}
Hello! now i need to map all properties of DocumentCategory (not just DocumentCategory.Id) How can i do it with your mapper? this solution map only last property:
public class SimpleMapper : EntityMapper<Document>
{
public SimpleMapper()
{
Property(x => x.DocumentCategory)
.ColumnName("CategoryId")
.ToPropertyValue(x => new DocumentCategory { Id = (int)x });
Property(x => x.DocumentCategory)
.ColumnName("CategoryDescription")
.ToPropertyValue(x => new DocumentCategory { Description= (string)x });
//other properties...
}
}
update: stored procedure result:
Id | Name | DocumentCategoryId | DocumentCategoryName |
---|---|---|---|
1 | myDoc1 | 1 | FirstCategory |
i tried like this
public void Map(IDataRecord source, object destination)
{
var doc= (Document)destination;
doc.Id = (int)source["Id"];
doc.Name = source["Name"].ToString();
doc.DocumentCategory.Id = (int)source["DocumentCategoryId"];
doc.DocumentCategory.Name = source["DocumentCategoryName"].ToString();
}
but fail with exception
Failed to cast column value to property value for 'ProjectName.Core.Entities.Document.DocumentCategory'.
There is no support.
There are two types two queries:
in these queries you just want to find the correct item and rarely want all the details. Thus a limited SQL query with typically information from the main table will do.
(i do the below in my repository method) For these query I first query the main table (document) to get the entity details. Then I query the child tables (documentcategory) to get all the details. Then I just add them to the main entity before returning.
var entity = _uow.First<Document>("id = @0", id);
var categories = _uow.ToList<DocumentCategory>("DocumentId = @0", id);
entity.Categories = categories;
Adding that functionality to the library would would make it a lot more complex.
Thank you!
i have 2 entity classes:
1 Mapper class
repository
stored precedure result
Exception: