1

I have multiple object and some of them go to one schema "NewObjects" and the other go to "OldObjects" I want to be able to make what the NewObjects Schema is configurable from config file. Is there a way? Here is what I have.

namespace IDJC.Domain
{


    [Table("Agency", Schema = "NewObjects")]
    public class Agency
    {
        public int AgencyId { get; set; }
        public string AgencyName { get; set; }
    }
}

1 Answer 1

1
+50

Yes, through fluent api. Check the part: Mapping an Entity Type to a Specific Table in the Database:

For example, if you create a setting in your project (through Properties->Settings) name MySchemaName, you will be able to access it in your DbContext derived class. So when you override OnModelCreating you will be able to do something like:

modelBuilder.Entity<Agency>()  
    .ToTable("Agency", Properties.Settings.Default.MySchemaName);
Sign up to request clarification or add additional context in comments.

1 Comment

:) no worries, hope it helps.

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.