DataBase First approach with Lazy Loading disabled?

1

I'm going to start a project and the Sql Server database already exists so I'll take the Database First approach as an example of this article Entity Framework Tutorial . Home I will create the .emdx file and import the respective tables TB_Customer, TB_Endereco, TB_Product, TB_Ticket, and other associated tables. Home Let's imagine that I will do the following:

static void Main(string[] args)
{
    clienteCTX context = new clienteCTX();
    var _model = context.cliente.where(x => x.clienteID).ToList()
}

The above query will return all Entities associated with the Client Entity, correct? Home Can I disable Lazy Loading so that I load expression lambda only data I really need using include ? :

If Yes as I Disable Lazy Loading in this scenario by adopting DataBase First ?

    
asked by anonymous 29.09.2018 / 23:59

1 answer

0

The simplest way is to directly disable Lazy Loading :

static void Main(string[] args)
{
    clienteCTX context = new clienteCTX()
    {
        Configuration.LazyLoadingEnabled = false
    };

    var _model = context.cliente.where(x => x.clienteID).ToList();
}

I think this form will also work in Database First (just as it works in Code First ).

SOen I also found this form, but never experienced it:

public static dynamic GetListaClientes()
{
    using (var context = new clienteCTX())
    {
        try
        {
            context.Configuration.ProxyCreationEnabled = false;
            return context.cliente.where(x => x.clienteID).ToList();
        }
        catch (Exception ex)
        {
            return null;
        }
    }
}
Entity Framework: How to disable lazy

loading for specific query?

    
01.10.2018 / 11:20