Reasonable practice for existing db with 75 tables - sql-server

I'm creating a new visual studio web site using MVC4/webapi that will go against a database of 75 preexisting tables (not perfect in terms of foreign keys, etc.). I'm thinking that I will create an ado.net entity data model and select all my tables. then, when my tables change I will do the "update model".
With my linq2sql projects, I always ran sqlmetal against all my tables all the time to keep things in sync and that worked fairly well.
Is my plan to have all my tables in one ado.net entity data model reasonable? what pitfalls might I run into? Is it better to have lots of ado.net entity data models? I've tried having multiple ado.net entity models in other projects and I seem to constantly be getting my connection strings doubled in my web.config.
I did do a search on SO and did not find any discussions that directly addressed my concern.

If you followed your plan, you would miss out on an opportunity to have an entity model simpler than your database model:
Your application almost certainly doesn't need all 75 tables.
You would be missing the opportunity to consider a series of 1-1 tables as a single entity
You would be missing the opportunity to use inheritance in your model
You would be missing the opportunity to keep junction tables out of your model
You would be losing one of the greatest advantages of Entity Framework over LINQ to SQL: it does not need to stay one-to-one with the database.

Related

When to Create DB and When to Create Schema

This seems a design question but I wanted to know if there is a pattern or design consideration we need to have where we would want to create a Database and not a new schema.
why not create one big database and separate schemas. Under what circumstance should we create a new database.
They are just logical divisions, so for the most part it's a matter of preference. There is one place where it's not a matter of preference: replication.
As of September, 2022, the unit of replication is the database. It's possible to specify which databases you want to replicate, but not which schemas within a database to replicate.
If you plan to replicate, you'll want to think about keeping only the schemas/tables that are important to replicate in one or more databases that get replicated and keep other data in databases that do not get replicated.
Another thought could be, In a large DWH Enterprise Solution,
There can be variety of flavours of tables which You can map to different databases. Sales DB, Master DB, Finance DB for ex. Then Inside DBs, You may want to have schemas for tables, views ,procedures and other object .

Do i need to define relationship in SQL Server database if i am using EF and Linq

I am working on a asp.net mvc project and using Linq for all my data related operations. In such cases, do I need to define relationship in the SQL Server database ??
I am using Entity framework and Linq so I think it doesn't matter if I create an E-R diagram(i.e defining relationship) or not.
By 'define relationship' I assume you mean 'Foreign key constraints'. It is always advisable to define constraints in order to maintain data integrity. You should also consider that the database for your project could probably be used by other applications in the future which might be based on other technologies than EF.
If you have relations in DB they will automatically be imported in your EF Model but you always have an option to create the associations manually in the EF Designer if you don't have relations in DB.
See How to manually add association in Entity Framework

How to put Database Tables in MVC Models

I'm new in developing in MVC and I have some doubts in how to build the Models. I don't know if I must build them in terms of Database Tables or in other terms.
I have for example this 5 tables:
Domain
Category_Domains
Countries_Domains
Categories
Countries
How can i Build a Models to do actions in these Database Tables. Should I built the SQL commands to Insert, Delete and Update for each one of these Tables or I should do other thing than this?
Sorry if I not explain well.
The best advice I can give you is to look into the entity framework. Using this framework, you can create a data connection to your SQL database and the framework will create your model based on your table structure, including relationships.
Doing this will ensure your database is modelled correctly and kept in sync at all times

Postgresql - one database for everyone, or one-database per customer

I'm working on a web-based business application where each customer will need to have their own data (think basecamphq.com type model) For scalability and ease-of-upgrades, I'd prefer to have a single database where each customer gets a filtered version of the data. The problem is how to guarantee that they stay sandboxed to their own data. Trying to enforce it in code seems like a disaster waiting to happen. I know Oracle has a way to append a where clause to every query based on a login id, but does Postgresql have anything similar?
If not, is there a different design pattern I could use (like creating a view of each table for each customer that filters)?
Worse case scenario, what is the performance/memory overhead of having 1000 100M databases vs having a single 1Tb database? I will need to provide backup/restore functionality on a per-customer basis which is dead-simple on a single database but quite a bit trickier if they are sharing the database with other customers.
You might want to look into adding Veil to your PostgreSQL installation.
Schemas plus inherited tables might work for this, create your master table then inherit tables into per-customer schemas which provide a company ID or name field default.
Set the permissions per schema for each customer and set the schema search path per user. Use the same table names in each schema so that the queries remain the same.

ASP.NET MVC Membership DB must be merged with site DB?

I am planning to use ASP.NET MVC2 implemented membership system to manage users. Database that uses application should have tables that are related with these users. Is it possible to use two different databases and make relationships (foreign keys) between them or I will have to merge these two databases into one?
Thanks,
Ile
It is NOT possible to put up relationships between databases. You CAN use triggers to ensure relational integrity.
Otherwise I would say: all in one database, put them into different schemata.
I would put membership/roles in a separate database. I don't think having foreign key constraints is that useful. Its better decoupling if you go through the membership API rather than join with the tables directly. The only thing in the membership database you might need to look up often is the username. If thats becomes a performance problem I'd probably just create an lookup table, either in memory or in a lookup table in the other component's database.

Resources