locked
SQL Server database connection class RRS feed

  • Question

  • User675943842 posted

    Hi,

    I am new to MVC and currently experimenting a bit creating a simple site with the register and login parts. Initially I created an empty MVC project, a SQL Server database project, and a data library class which utilized Dapper for database IO. I was handling the register and login etc without using any boiler plate code.

    I noticed that if I enabled Authorization for individual users in the project creation stage, then you basically get all the register and login with authorization for free out the box! So I created a new project using this method, and migrated the MDF database to a separate SQL Server project under the same solution. However, I'm now wanting to extend the functionality of the project to add additional database tables.

    So I'm wondering, what is the best way to now interact with the new SQL Server database tables ? Should I reuse my initial database classes which use dapper, and allow for fairly easy programming of the database IO, or, is there another technique which is recommended? At some point, I will also add the Web API, so would like to re-use database classes as much as possible.

    At the moment I'm thinking:-

    Account Management (register, login, password reset etc.) - Use boiler plater code for the MVC and Web API

    Additional functionality (i.e. CRUD database operations) - MVC and Web API talk to Dapper database wrapper class, secured via initial Authorization functionality.

    A further question I have is, should all 'talking to' the database be done async?

    Thanks for any opinions,

    D

    Tuesday, October 15, 2019 12:08 PM

All replies

  • User475983607 posted

    You have two different databases one contains the Identity data store using EF and the other is application specific using Dapper?

    Account Management (register, login, password reset etc.) - Use boiler plater code for the MVC and Web API

    Sounds fine.

    Additional functionality (i.e. CRUD database operations) - MVC and Web API talk to Dapper database wrapper class, secured via initial Authorization functionality.

    Also sounds fine.

    A further question I have is, should all 'talking to' the database be done async?

    You should always use async when when applicable. 

    Tuesday, October 15, 2019 2:48 PM
  • User675943842 posted

    Hi, thanks for your reply. I was planning on just using the one database for everything. But, maybe it is better to keep the Identity store separate? Sounds like I'm on the right track thus far then which is good :)

    Tuesday, October 15, 2019 5:57 PM