Click here to Skip to main content
14,920,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi ,
Ihave one to many relatioin with section and category
category and subcateogry
and category to item , subcategory to item
in using EF code first and setting fluent api as

modelBuilder.Entity<Section>().HasMany(p => p.Categories).WithRequired().HasForeignKey(a => a.SectionID);
            modelBuilder.Entity<Category>().HasMany(p => p.Items).WithRequired().HasForeignKey(a => a.CategoryID);
            modelBuilder.Entity<Category>().HasMany(p => p.Subcategories).WithRequired().HasForeignKey(a => a.CategoryID);
            modelBuilder.Entity<Subcategory>().HasMany(p => p.Items).WithRequired().HasForeignKey(a => a.SubcategoryID);

please answers the questions
1. is this correct accoring to relationship
2. what will be code for one to one and one to 0..1 relationship

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900