How do I get the EntityFramework to check for 2 parameters?

前端 未结 2 1094
余生分开走
余生分开走 2021-01-27 23:46

I have 3 related objects (non relevant properties omitted for brevity):

public class Product
{
    public int ID { get; set; }
    public virtual ProductPrice Pri         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 00:28

    I was never able to figure out how to fix the models or use the fluent API. I did some lazy loading instead. If anyone has a better solution, please post it.

    public class Product
    {
        public int ID              { get; set; }
        public string Manufacturer { get; set; }
        public string Model        { get; set; }
        public string PartNumber   { get; set; }
        public int CategoryID      { get; set; }
        public string Description  { get; set; }
    
        public int VerticalID = 1;
        private ProductPrice _price;
    
        public virtual ProductCategory Category { get; set; }
        public virtual ICollection Images { get; set; }
        public virtual ICollection Documents { get; set; }
        public virtual ICollection Details { get; set; }
        public virtual ICollection RelatedProducts { get; set; }
    
    
        // Lazy Loading
        public ProductPrice Price
        {
            get
            {
                if (_price == null)
                {
                    var db = new ApplicationContext();
                    _price = db.Prices.FirstOrDefault(p => p.ProductID == ID && p.VerticalID == VerticalID);
                }
    
                return _price;
            }
        }
    }
    

提交回复
热议问题