Create Bank Automatically with Code First

Asked

Viewed 547 times

-3

I am creating an ASP.NET MVC application with Code First. This system is trade management software. I’d like to separate the information from each company, not leave it all in the same bank. We initially thought about leaving everything the same, but we thought about the performance issue. The bank would grow big, and it would take time to perform some things.

I thought about creating the bank for the first login of that company, and then with the logged-in user he could register the other users. He would be like the "Master" of the company. Then the other users he registers would go to a bank of Logins where it would have a field that identified the company of that user, and accessed the bank of the same. I would only create the bank for the first user of the company.

This is possible?

  • 1

    Welcome to theOpt. What you have tried to do?

  • I haven’t found anything on the Internet yet. I was able to use "Database.Createifnotexist()" in the Context of my database to automatically create when running my application. But it only creates the database present in my Web.Config. I know that for Desktop, it is possible to change the App.Config and connect me to a different bank. But I don’t know how to do this on MVC, or how to create different banks at runtime.

  • Why create a bank, not a table? I couldn’t see the need to create a bank for each user.

  • This system is a trade management software, I would like to separate the information of each company, and not leave everything in the same bank. We initially thought about leaving everything the same, but we thought about the performance issue. The bank would grow a lot, and it would take time to perform some things. As I should do in this case?

  • The approach I use is to keep everything in the same bank and create a 'Company' entity where you can register the head office and subsidiaries. Think of the following situation: an affiliate may have more than one user. In that case you would actually create a bank for each user?

  • I thought about creating the bank for the first login of that company, and then with the logged-in user he could register the other users. He’d be like the "Master" of the company. Then the other users that he registered would go to a Logins database where he would have a field that identified that user’s company, and accessed the user’s bank. I would only create the bank for the first user of the company, you know?

Show 1 more comment

2 answers

2

This only makes sense if you have one deploy system by company. Therefore, it would have a company base by system.

If the idea is to serve a single system to several companies, your idea just doesn’t make sense. High data volume would only affect performance if you structure your database wrong, which is very difficult within the Entity Framework because it forces you to structure your database correctly.

Anyway, the right way to do this you want is to put this initial user on Migrations/Configuration.cs, method Seed. It is there that initial insertions are made, as users of banks and minimum information of other entities.

Furthermore, the structuring of the database should take into account that information belonging to an enterprise needs to be linked to an enterprise entity. This is elementary modeling of the bank and there is no need to explain this in the answer. Already for access restrictions per company you can find examples of how to do it here.

2

Using two dbContext would be simple, one for the registration of companies (accessing a fixed bank) and another for the specific bank of the company (dynamic bank), the second could read or create the Connectionstring based on the registration of companies.

The Master user would be registered together with the Companies and would be added to the specific database in the Seed method.

When Login was done, the company is chosen and this directs to which bank to connect

Browser other questions tagged

You are not signed in. Login or sign up in order to post.