locked
Specify Table / Schema for Foreign Key RRS feed

  • Question

  • How can we specify storetablename for a foreign key ?

    specifically, I would like to specify schema for the table to map my foreign key to.

    Thanks

    Zaki


    VB Star
    Friday, July 23, 2010 2:25 AM

Answers

  • Zaki,

     

    You can specify a schema and tale name for an entity type using the fluent API on ModelBuilder like this:

     

        modelBuilder.Entity<Product>().MapSingleType().ToTable("myschema.MyProduct");

     

    If you are using DbContext you can do this by overriding the OnModelCreating method:

     

        protected override void OnModelCreating(ModelBuilder modelBuilder)

        {

            modelBuilder.Entity<Product>().MapSingleType().ToTable("myschema.MyProduct");

        }

     

    Hope that helps.

     

    Thanks,

    Arthur

     

    Wednesday, July 28, 2010 6:57 PM
    Moderator