EF Core FromSql for same model but with different queries and extra columns

.net-core asp.net-core entity-framework-core

Question

Let's say I have C# class Operation

public class Operation 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Code { get; set; }
    public string Description { get; set; }
}

Using EF Core FromSql I want to use it for multiple queries. All good then I write select my self. But the problem I am facing, is that there are stored procedures that I cannot change. And these stored procedures does not return all columns needed for my class.

For example SP_1 returns Id, Name and Code. SP_2 returns Id, Name and Description.

Is there any way that I can set these properties to some default or dummy values? Or just ignore these optional properties, but map to class when they are being returned from database?

1
2
8/16/2019 7:13:10 AM

Popular Answer

you can map your data to a DTO (Data Transfer Object).

This DTO can be customized depending on your needs

You can map any field you want to output from the entity to the special DTO

This mapping can be done manually or by an automapper

3
8/16/2019 8:21:04 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow