Home > Articles > Details

The expression 'b.listOfFileRecords' is invalid inside an 'Include' operation, since it does not represent a property access

Question: System.InvalidOperationException: 'The expression 'b.listOfFileRecords' is invalid inside an 'Include' operation, since it does not represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, use casting ('t => ((Derived)t).MyProperty') or the 'as' operator ('t => (t as Derived).MyProperty'). Collection navigation access can be filtered by composing Where, OrderBy(Descending), ThenBy(Descending), Skip or Take operations. For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393.'

Login to See the Rest of the Answer

Lets look at why this error occurs, first the error message is telling you that the Model (POCO) you have defined has no proper navigation between the Entity you want to include from one Model Class.

Take a look in the example:

  public partial class MyModal
        public int Id { get; set; }
        public string SomeProperty { get; set; }
        //This is where the error is, there is no proper navigation between MyModal and MySubClass
        //For this navigation to work, you need MyModalId in the MySubClass Modal Class
        //Likewise, the Property has to exist in the Database as well. You have to know the relationship between the two, is it one to one or one to many or many to many. All that matters.
        public MySubClass listOfFileRecords { get; set; } 

If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Mark said:

If you still have the error even after following the instruction, remove the "[NotMapped]" directive and you won't have an error anymore.

Posted On: January 20, 2022 13:34:57 PM

© 2022 - ErnesTech - Privacy