Entity Structure 6 Lazy Boot Weirdness

I have a poco class that is connected to an entity infrastructure. The class is called PersonalizationCatalogPrice. This class has a subelement called Pricelevel, which does not have a virtual keyword on it. Because of this (based on my understanding) this object should never be lazy and should return null. However, we found that this object seems to load when used in a certain way.

therefore the main structure of the class is

public class PersonalizationCatalogPrice
    {
        public int PersonalizationCatalogPriceID { get; set; }

        public int PersonalizationCatalogId { get; set; }

        public virtual PersonalizationCatalog PersonalizationCatalog { get; set; }

        public decimal CustomerRetail { get; set; }

        public decimal ConsultantCost { get; set; }

        public decimal PersonalVolume { get; set; }

        public decimal QualifyingVolume { get; set; }

        public int PriceLevelId { get; set; }

        public PriceLevel PriceLevel { get; set; }
}

. Iqueryable of PersonalizationCatalogPrice. IQueryable, priclevel iQueryable (. " pcp.pricelevel" ). , pricelevel , .

IQueryable<PersonalizationCatalogPrice> allPersPriceRecords = _e2ReposMan.PersonalizationRepository.GetSomeRecords();

//List<PersonalizationCatalogPrice> persprices = allPersPriceRecords.ToList();

var persQuery = from pl in personalizationLines
                join pcp in allPersPriceRecords on pl.Item2.PersonalizationCatalogPriceID equals pcp.PersonalizationCatalogPriceID
                where !HostessPriceLevelTypes().Contains(pcp.PriceLevel.PriceLevelTypeId)
                select pl.Item2.PersonalVolume * pl.Item1;

var openOrdersTotal = (query.Any() ? query.Sum() : 0) + (persQuery.Any() ? persQuery.Sum() : 0);

, , ToList(). null , , , . (EF 6)

- , , toList().

.

+4
1

, , PriceLevel null, .

, , .

, . Include(). . , , , , ToArray() ToList() , . , , , - .

, null, DbContext, . , , , DbContext.

, , Load() - .

, , AsNoTracking(). , , , , .

+1

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


All Articles