locked
Code-First: Why can't we configure navigation property as required via Fluent API? RRS feed

  • Question

  • hi

    With Code-First we're able to configure navigation property as required via Data Annotation [Required] attribute. But we're not able to also configure navigation property as required via Fluent API, since  EntityTypeConfiguration<T>.Property() overloads only accept struct types, while navigation property has a class type.  Is there a reason why Fluent API doesn't support this feature or did microsoft team simply forgot to include it in Fluent API?

    Thank you

    Wednesday, December 12, 2012 9:18 PM

Answers

  • Hi,

    As far as I know, you are not possible to do this with fluent API, because for many to many mapping, EF creates a join table to store the key pairs which are not null. 

    • Marked as answer by Alexander Sun Wednesday, December 26, 2012 2:29 AM
    Friday, December 14, 2012 9:25 AM

All replies

  • Hi,

    As far as I know, you are not possible to do this with fluent API, because for many to many mapping, EF creates a join table to store the key pairs which are not null. 

    • Marked as answer by Alexander Sun Wednesday, December 26, 2012 2:29 AM
    Friday, December 14, 2012 9:25 AM
  • Hi,

    Have you tried HasRequired ? Try "Using HasRequired to help when there is no foreign Key property"' from

    http://msdn.microsoft.com/en-us/data/hh134698.aspx


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Friday, December 14, 2012 11:47 AM