0

I have a classes structure something like that:

public class Customer{
         public AgreementDetails Agreement { get; set; }
}

[ComplexType]
public class AgreementDetails{
    public int SalesPersonId { get; set; }
    [ForeignKey("SalesPersonId")]
    [NotMapped]
    public virtual SalesPerson Sales { get; set; }
}
public class SalesPerson
{
...
}

When I'm displaying the list of customers, i'm calling Sales property to disaply sales person details but property is null, usually for navigating properties this can be avoid using .Include method but it doesn't work in my case, so the query is

List<Customer> res = db.Customers.Include(c=>c.Agreement.Sales).ToList();

The exception is:

A specified Include path is not valid. The EntityType 'CodeFirstNamespace.Customer' does not declare a navigation property with the name 'Agreement'.

1 Answer 1

1

I found the answer: complex types shouldn't contain navigation properties (as well as foreign keys).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.