Last post Nov 05, 2019 03:23 AM by Yongqing Yu
Member
75 Points
161 Posts
Nov 01, 2019 12:43 PM|Prathamesh Shende|LINK
Lambda expression used in INCLUDE which is not valid - this error is showing this code this my code
How do i solve this I want to select only those record who's dealstatus will be 1
ViewBag.Stages = _context.Stage.Include(a => a.Deals.Where(a=>a.DealStatus == 1)).ToList();
public class Deal { public Deal() { this.DealLosts = new HashSet<DealLost>(); } public int ID { get; set; } [Required] public string Name { get; set; }public int DealStatus { get; set; } public virtual Stage Stage { get; set; } }
public class Stage { public Stage() { this.Deals = new HashSet<Deal>(); } public int ID { get; set; } [Required] public string Name { get; set; } public string BackgroundColor { get; set; } public virtual ICollection<Deal> Deals { get; set; } } }
All-Star
52971 Points
23574 Posts
Nov 01, 2019 02:26 PM|mgebhard|LINK
You are not following the openly published documentation for querying related entities.
https://docs.microsoft.com/en-us/ef/core/querying/related-data
Contributor
3710 Points
1043 Posts
Nov 04, 2019 06:50 AM|Yongqing Yu|LINK
Hi Prathamesh,
According to your code , you can try to change your code like this :
ViewBag.Stages = _context.Stage.Include(a => a.Deals.Where(c=>c.DealStatus == 1)).ToList();
You can refer to this link : Loading Related Entities
Best Regards,
YongQing.
Nov 04, 2019 12:44 PM|Prathamesh Shende|LINK
Not Working like this
Nov 05, 2019 03:23 AM|Yongqing Yu|LINK
Hi Prathamesh ,
According to your description, you can try this code :
ViewBag.Stages = _context.Stage.Where(a => a.Deals.Any(c=>c.DealStatus == 1)).ToList();
You can also refer to this link : https://stackoverflow.com/a/3548943
Member
75 Points
161 Posts
Lambda expression used in INCLUDE which is not valid - ASP.net Core mvc
Nov 01, 2019 12:43 PM|Prathamesh Shende|LINK
Lambda expression used in INCLUDE which is not valid - this error is showing this code
this my code
How do i solve this I want to select only those record who's dealstatus will be 1
All-Star
52971 Points
23574 Posts
Re: Lambda expression used in INCLUDE which is not valid - ASP.net Core mvc
Nov 01, 2019 02:26 PM|mgebhard|LINK
You are not following the openly published documentation for querying related entities.
https://docs.microsoft.com/en-us/ef/core/querying/related-data
Contributor
3710 Points
1043 Posts
Re: Lambda expression used in INCLUDE which is not valid - ASP.net Core mvc
Nov 04, 2019 06:50 AM|Yongqing Yu|LINK
Hi Prathamesh,
According to your code , you can try to change your code like this :
ViewBag.Stages = _context.Stage.Include(a => a.Deals.Where(c=>c.DealStatus == 1)).ToList();
You can refer to this link : Loading Related Entities
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
75 Points
161 Posts
Re: Lambda expression used in INCLUDE which is not valid - ASP.net Core mvc
Nov 04, 2019 12:44 PM|Prathamesh Shende|LINK
Not Working like this
Contributor
3710 Points
1043 Posts
Re: Lambda expression used in INCLUDE which is not valid - ASP.net Core mvc
Nov 05, 2019 03:23 AM|Yongqing Yu|LINK
Hi Prathamesh ,
According to your description, you can try this code :
You can also refer to this link : https://stackoverflow.com/a/3548943
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.