To connect an external table to an EF-Core model, follow these steps:
Create a new class in your project which represents the table you wish to connect to. This class should contain properties that map to the columns in the table.
Create a new DbContext class or modify your existing DbContext class to include a DbSet property that corresponds to your new class.
Modify the OnModelCreating method of your DbContext to include a mapping between your new class and the table in the database. This can be achieved using the modelBuilder.Entity method.
In your application startup code, add a call to the AddDbContext method of the services collection, passing in an instance of your DbContext class.
You can now use the DbSet property in your DbContext to query and manipulate data in the external table.
Note: If the table is not part of the same database as the other tables in your DbContext, you may need to create a new DbContext specific to that database, and connect to it separately.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-05 10:04:45 +0000
Seen: 17 times
Last updated: Jun 05 '23
What is the process for obtaining and recording all Linq To Db queries in a database table?
What is the process of accessing a URL within a Class Component?
What is the process for terminating a task using C#?
What is the process of separating Swing listeners?
What is the process for invoking a method in a class by its name while passing arguments?
What is the process for incorporating std::hash into a class template?
What is the process for adding a class path permanently to the Mac terminal?