Ask Your Question
3

What is the process for connecting an external table to an EF-core model?

asked 2023-06-05 10:04:45 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-05 10:27:02 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-06-05 10:04:45 +0000

Seen: 17 times

Last updated: Jun 05 '23