Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To connect an external table to an EF-Core model, follow these steps:

  1. 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.

  2. Create a new DbContext class or modify your existing DbContext class to include a DbSet property that corresponds to your new class.

  3. 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.

  4. In your application startup code, add a call to the AddDbContext method of the services collection, passing in an instance of your DbContext class.

  5. 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.