How mapping many-to-many with additional columes in NHibernate - c#

Please I do not know how to map "projekt_etapa" see on picture. it is Many to many, but I have there some another columes. So I do not know If i have tu use bag or make class for it. thank you so mutch.

This is definitely a duplicate of several other questions on StackOverflow. These are 3 of the many.
nhibernate many-to-many mapping - additional column in the mapping table?
additional fields in NHibernate many-to-many relation tables
Fluent Nhibernate Many-to-Many mapping with extra column
Brought to you by google:
site:StackOverflow.com nhibernate many to many additional columns

Related

How does the database represent One-to-One relationship?

I am using a simple One-to-One relationship in entity framework core 2.0.
modelBuilder.Entity<Profile>()
.HasOne(p => p.Avatar)
.WithOne()
.HasForeignKey<Profile>(p => p.AvatarId);
Where every profile has only one avatar.
Looking in database managing apps does not show me (or at least I did not find) any differences between One-to-One and One-to-Many relationships. So what I mean I could not find any special constrains for One-to-One different that One-to-Many.
How does the database know which kind of relationships I defined? If it does not know, why would I then define the type of relationship I am using?
If you can't see any foreign keys or primary keys in your database then it doesn't know. Or more specifically: it you will be allowed to save data which violates the relationship.
Integrity of relationships are enforced in databases with Foreign Keys but this certainly does not stop you submitting SQL which joins tables incorrectly.
Here's a link to defining foreign keys that ensures that a one to one relationship is guaranteed based on the data in tables. http://www.tech-recipes.com/rx/56738/one-to-one-one-to-many-table-relationships-in-sql-server/ .

Entity Framework Composite Key

I have a database with two tables, customer and account. Because multiple customers can exist on multiple accounts this is a many to many design.
This is how I designed it in SQL
This works quite nicely as Entity Framework picks up that its a mapping table and just maps Customer to Account as lists on each and hiding the mapping table. Brilliant!
I would like to extend this further to add preferences to a mapping between a customer and an account like such:
Am I right in assuming this is not possible? I have tried adding it to EF model but instead it brings back the mapping table.
Anyone else had any luck with this?
What you have in your first case is a simple many to many relation table, which in Entity Framework results in the collections of entities on one another.
If you want to have a relation to the Preference from your CustomerAccount relation table, the relation becomes complex and it cannot be depicted in the simple relation lists anymore. You need add an entity for your relation CustomerAccount which will have foreign keys on Customer, Account and Preference.

Explicit many to many join table in Entity Framework 4

By default EF hides a many to many join table that does not contain additional data than the foreign keys to the joined tables.
Is it possible to tell EF (and the designer) to explicitly create the join table and make it usable in code?
Thanks
No EF designer will not add this entity for you. If you want junction table exposed you must manually delete created relation and add junction table's entity and two one-to-many FK relations. Here are related questions with step by step guide:
How to expose the join table in many to many relation
How to get Entity to Table mapping for many to many relations

Linq to SQL many to many Relationships - Insert Update & Delete

I have a database that relies on a bunch of Many-to-Many and rather than denormalizing the whole database (which is quite large) I would like to know if there is a SIMPLE way of implementing Many-to-Many Relationships using LINQ-to-SQL Yet...
Everywhere I look I find articles on HOW Difficult It is, or A Simple Workaround that is actually "NOT" Simple. But all the articles I have been able to locate are pretty dated, using asp.net 3.5.
Should I just Create a Stored Procedure and then Drag it into the .DBML file as a method?
So I guess my question is:
Is there any new way to implement many-to-many using Linq-to-Sql in ASP.NET 4.0 along with MVC 3.
Examples of usage in my Project:
In the finished model, there will be Other Tables linked to the Many-to-Many Tables (i.e. EventAddress, EventUrl, VipAddress, VipPicture, GuestAddress, GuestPhone, GuestEmail, etc...)
So you can see when this would be a pain in the a$$ to denormalize.
Thank you,
Tim
Have you considered using Entity Framework?
It handles m:n relationships nicely. In your case the EmployeeAddress table would be abstracted away as a list of addresses on your Employee object.
It is also my impression that linq to sql isn't really a priority for Microsoft, EF Is.
I understand if you do not wish to convert an existing project, but for new projects EF4 would probably be a better fit.
LINQ to SQL will always map directly to the structure of the database. If your database has all of those junction tables, then they will be in your LINQ to SQL model - period.
Although you can map many-to-many relationships in both LINQ to SQL
and LINQ to Entities, LINQ to Entities allows a direct mapping of
many-to-many relationships with no intermediary class, while LINQ to
SQL requires that an intermediary class map one-to-many to each of the
classes that are party to the many-to-many relationship.
link to the quote above - http://msdn.microsoft.com/en-us/library/cc161164.aspx

Do I need to include all fields in my entity framework model

Quick question for everyone:
Do I need to include all the database table fields on my EF model?
For example; I've created a sub-model that only deals with tblPayment and associated tables. Now, I need to write a LINQ query to get some information about items. I would typically get this by joining tblPayment to tblInvoice to tblInvoiceItem to finally tblOrderItem.
I'm wondering if when I add in those other tables, do I need to include all the fields for tblInvoice and tblInvoiceItem? Ideally; I'd just like to keep the fields I'd need to join on, as that would limit the possibility of my sub-model breaking if other fields on those tables are modified/deleted.
Can I do this?
No, you don't need to include them all.
However, the GUI mapping tool, when reverse-engineering an existing DB into an EF model, will always include all columns, and there's no way to tell it not to.
Therefore, to exclude columns, you must do one of the following
Manually edit the EDMX yourself. Simply deleting the columns in the GUI designer may work, but only removes the columns from CSDL, not SSDL. The EF may or may not let you do that, depending upon the column's SSDL mapping.
Generate the model from a different DB, which has a similar schema except that it lacks those fields.
Code-first or model-first (EF 4 only).
Yes, you can remove other fields from the entities.
You can not only remove fields from entities, your entities can be combinations of different tables.
Entity Framework

Categories