Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

ADO.NET entity data model - problem with foreign keys

$
0
0

Im using the ADO.NET entity data model wizard to create a bunch of POCO's from my database.  I choose the code first from database option, then select the tables i require.  The 'include foreign key columns in the model' option is greyed out but checked. When I check my dbcontext model thats generated, i have all the Dbsets I selected, but only 2 tables have the modelbuilder properties set in the OnModelCreating method

modelBuilder.Entity<Contact>()
                .HasMany(e => e.ContactOrgAuthoriseds)
                .WithRequired(e => e.Contact)
                .HasForeignKey(e => e.ContactID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Contract>()
                .HasMany(e => e.ContractSites)
                .WithRequired(e => e.Contract)
                .HasForeignKey(e => e.ContractID)
                .WillCascadeOnDelete(false);

There are many, many more tables with foreign keys but the process hasnt picked them up, anyone know why this should be ?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>