Convert Entity Framework sql structure to class yourself

I got the code first by EF, and I want to use my own sql for more complex select statements. When I try to execute:

using (VaultsDbContext db = new VaultsDbContext())
{
   var contracts = db.Contracts.SqlQuery("select * from Contracts").ToList<Contract>();
}

I got:

Unable to create value for MetaProps property of type 'DskVault.Models.DbModels.MetaProps'. Only properties of primitive or enumerated types are listed.

MetaPropsis a class that contains deleteflag, creator, etc., and it is a property of all my classes. It does not map to another table, each table has deleteflag, createor, etc.

public class Contract
{
    public long Id { get; set; }
    ...
    public MetaProps MetaProps { get; set; }
}

Is there a way to map from the class’s own sql if the class contains a complex type or if EF does not support this? Also, what if a complex type is an object mapped to another table (join)?

Edit: Version: Entity Framework 6

+4
1

, . , . SEPARATE Entity Framework Power? Nuget, , , . , .

+1

Source: https://habr.com/ru/post/1525267/


All Articles