public static Beer ToEntity(this BeerBinding binding, MainContext context, Beer beer = null) { var b = beer.DefaultIfNull(); b.Abv = binding.Abv; b.Name = binding.Name; b.ValueId = beer?.ValueId ?? binding.Name.ToValueId(); b.BeerBrandId = string.IsNullOrWhiteSpace(binding.BrandId) ? b.BeerBrandId : context.BeerBrands.GetId(binding.BrandId).Value; b.BeerStyleId = context.BeerStyles.GetId(binding.StyleId); return(b); }