ASP.NET database which relations - database

Is it good approach to make this way database in ASP.NET MVC?
I am using intermediary ention between entions instead many to many relation.
Should I use relations many to many and use generic?

It is fine,
you have to do a bit more work manually, but you gain control over your entities.
A many-to-many relationship requires an intermediary table to make the associations.
If you use a many-to-many relation, EF will create an intermediary table anyway

Related

3-Way Relation or Relation with Relation in Laravel?

I'm puzzling over how to set up this relationship in Laravel, (I'm converting a legacy app):
I have Repair Shops, which provide different types of repairs, on different brands of vehicles.
For example, Shop A might repair Brakes but not Exhaust Systems for Ford vehicles. Shops are required to say what services they provide, (Exhaust repair), but adding a brand is optional. I have Shop, Service, and Brand tables in the DB. Shop and Service have a belongsToMany relationship using the provides_service pivot table. In the legacy system I have a 3-way pivot table to specify what Services can be done to each Brand in each Shop.
Laravel doesn't seem to do 3-way relationships well, (or does it? If so, point me there!). So, I feel like it would make sense to create a belongsToMany between the provides_service relation and the Brand. So, is there a way to set up a relationship between a Model and another Relationship in Laravel, or do I have to create a ProvidesService model? Creating a ProvidesService model seems wasteful, but I'm not sure what else to do here.

Does a Normalized Class Design Lead to a Normalized Database Design

Motivation: I am a solo developer so I take all kinds of roles during development from programming to UI design to database design, etc. (it is pretty exhausting). We all know that one person can't be good at everything (or many things) and another thing I know for sure is that databases should be well designed and normalized.
Assumption: Assume that I am a very good object-oriented developer and I design my domain models following best practices (e.g. SOLID) and patterns.
Question: If my domain model is very well designed and I used an ORM (e.g. Nhibernate, Entity Framework, etc.) to generate the database from that model, will the generated database be normalized?
Generated database will depend on your entities mapping. If you are asking about default mapping, which will be used, then generated database could be not normalized.
For example, if you have nice inheritance hierarchy by default Entity Framework will use table per hierarchy (TPH) mapping, which enables polymorphism by denormalizing SQL schema. TPH uses discriminator column to store all types from hierarchy in single table. TPH violates third normal form because discriminator column is not part of primary key, but some columns depend on discriminator value.

Does SQL Server have native support for EAV

I love the flexible schema capabilities of CouchDB and MongoDB, but I also love the relational 'join' capability of SQL Server. What I really want is the ability to have tables such as PERSON, COMPANY and ORDER that are basically 'open-schema' where each table has an ID but the rest of the columns are defined json-style {ID:12,firstname:"Pete",surname:"smith",height:"180"}, but where I can efficiently join PERSON to COMPANY either directly or via a many-to-many xref table. Does anyone know if SQL Server has any plans to incorporate 'open schema' in SQL, or whether Mongo or Couch have plans to support efficient joining? Thanks very much.
CouchDB offers a number of ways to establish relationships between your various documents/entities. Check out this article on the wiki to get started.
The tendency, when coming from a relational background, is to continue using the same terminology and mindset whenever you try to solve problems. It's very important to understand that NoSQL solutions are very different, otherwise they have no real purpose for existing. You should really seek to understand how these various NoSQL solutions work so you can compare them with your application's requirements to see if it's an appropriate fit.
MongoDB = NoSQL = No Joins - never ever.
If you need JOINs due to your data model or project requirements: stay with a RDBMS.
Alternatives in MongoDB:
denormalization
using embedded documents
multiple queries
As much as this would be inefficient to Query on a large scale, from a technical standpoint, using the XML datatype would allow you to store whatever structure you wanted that can vary by row.
Not that I'm aware of, but it's not that hard to role your own EAV, it's only 3 tables after all :)
Entity stores the associated table name.
Attribute stores the column name, data type and whether it's nullable.
Value contains one nullable column for each required data type.
Entity 1..* Attribute 1..* Values
Assuming you're using .NET, define your EAV interfaces, create some POCO's and let Entity Framework or your ORM of choice wire up the associations for you. LINQ works great for this sort of operation.
It also allows you to create a hybrid model, where parts of the schema are known but you still want flexibility for custom data. If you design your domain model with this in mind (i.e. use the EAV interfaces in your model) the EAV can be baked in to the EF data context (or whatever) to automate the loading of attributes and their values for each entity. Your EF entity just needs to know which table entity it belongs to.
Of course it's not the perfect solution, as you're (potentially) trading performance for flexibility. Depending on the amount of data you want to persist and the performance requirements, it may be more suited to models where most of the schema is known and a smaller percentage is unknown. YMMV.

Many-to-many relationship in .NET RIA services

I have a many-to-many relationship in my database of objects A to B. When i create a domain service the metadata looks fine. A has a collections of Bs, B has a collection of As. So it is correct. However the *.g.cs file generated doesn't have the same relationship.
Is there a way to make it work? I googled some answer to actually generate objects for the association table but i am curious if i can avoid this.
Thanks
In the current release/version of RIA Services, you'll need the association table. We will most definitely be looking into this of course for a future release.
That said, I think often many-to-many relationships often have some interesting data associated with the relationship and as such, the middle table often has a real use, rather than existing for the sake of existing.
Till MS implements it in RIA, you can use http://m2m4ria.codeplex.com/
We have used in one of our Silverlight/RIA projects for User/Role (many-to-many) relationship and worked fine.

Is it good practice to have a table referenced by two different entities?

I am building a application with these patterns: Silverlight, RIA, EF, Prism, SL Unit Testing.
This project will have lots of entities and lots of modules referencing those entities. Each entity is in its own RIA Service Library along with the RIA domain service and associated metadata.
I am running into problems when I reference a certain table in two different entities. For example table bar exists in entity1 and entity2.
My Question: Is it good practice to have the same table in multiple entities (.edmx files)?
If so what are good ways to avoid them causing a mulitple reference error?
If not what do I do when I need that table in another entity?
Normally, when you start working with EF (and most ORMs), you tend towards having an entity-per-table relationship, or at least, a table->entity hierarchy relationship, if you have inheritance in your entities.
If you're trying to refer to the same table from 2 separate entity types, you probably need to pull out a shared, single entity type that's refered to by both of your other entities.

Resources