Entity Framework association with multiple tables - c#

I have the following model with 3 tables and I'm attempting to create an association to the third table CustomerPart which uses a compound key from both of the other tables.
CustomerPart should be accessed via a key of CustomerNo from ShopOrder and Site/CatalogNo from SalesPart.
The only thing I've been able to come up with so far is to create an association from SalesPart to CustomerPart and in code manually select records where CustomerNo on CustomerPart matches the CustomerNo on ShopOrder.
Is there a way to create an association and navigation property for this or am I out of luck?

Related

EF6 Table Splitting with foreign keys (Database first)

I'm currently investigating the possibility to use table splitting with EF to stop pulling too many columns for nothing. As for now, I'm able to create a new entity, cut/paste the fields into the sub-entity and map it without much problems.
However, if one of those fields is a FK in the master table, it gives me the following error
"Running transformation: There is no property with name 'IdDocumentImportSource' defined in type referred by Role 'DocumentImports'."
I do understand that the both tables have a NavigationProperties that cannot be resolved anymore by the association FK because the field has been moved to the child table.
Here's my question; Is there a way to automaticaly move the association FK to the child table? I could only make it work by manually deleting the association, both navigation properties, creation the association FK of the child. It involves quite a lot of work on my part if I have to do all this manually for every association FK I got...!
DocumentImports is the ParentTable that I splitted into a new child table DocumentImports_StatusDetail and DocumentImportSources is the table being referenced by the FK.
Thanks!

create one to one REFERENCES in EF designer?

I have two tables employees and aspnetUser. I'm trying to create an Associate between tables employees and aspnetUser in EF designer in VS2013 using email from employees and username(email).I createUNIQUE Constraint on employees email to have UNIQUE email for each employee I have Problem when click ok I have this error message "verify that the navigation property name is unique" I have couple of Problems.
1-I try to use ID from asp.net membership but it is varchar(128) not guid because of that I have to change my employees ID from int to varchar(128) to very table have relation with employees.
2- how to solve this problem apically I don't have access to database because the easy thing is to create REFERENCES CONSTRAINT between users and employees I really don't have access to database because of company ?
The error tells you that you're introducing new navigation properties with names that already exist in the types you're trying to associate. In the text boxes below the Navigation Property checkbox you're not selecting properties. You're entering names for the new ones you've indicated you want to create by checking the checkboxes.
This is not going to work. If the types of the primary keys are different, EF won't be able to create a "soft" association between them (where a "soft" association is one that is not backed by a hard foreign key in the database).
You only option is to manually join the two tables whenever you need data from both.

Telerik Data Access One To Zero One association

I am trying to make One To Zero One association between two tables in Telerik Data Access, but can't make it work. Here are my tables:
Student
Id (PK)
Name (string)
BackPack
Id (PK)
StuffInside(string)
StudentId (Unique, Foreign key)
StudentId in Backpack references to Id in Student. When I do the mapping for some reason Telerik is making it One to Zero Many. I need One To Zero One.
I assume you are using the Telerik Data Access Visual Designer to model your database? If so, in order to create one-to-one association you need to specify that the ID from one table (Students) matches the ID from the other table (BackPacks). This way each student will have exactly one (or zero) backpack. Please refer to this documentation article which demonstrates the approach.
If this is not applicable in your scenario and you have to match the Student ID to the BackPack StudentId to achieve the same effect you could create one-to-many association and then manually create the unique constraint on the database server side. Alternatively you could switch to Fluent Mapping which allows you to create custom indexes in you mapping.

Add Navigation Property Manually to Entity Framework

I need to add a navigation property between two Entities TableA and TableB
TableA
ID : Primary Key
Code: String (Allows Null)
TableB
BID: Primary Key
Code: String (Allows Null)
Now I want to add a navigation property to these Entities which are related by the code which is not a foreign key. Can anyone tell me how this is possible
It is not possible because code is not PK in any of your tables. Navigation properties follows same rules as database relations - in principal table you must use PK and in dependent you specify FK. Databases also offers selecting unique key in principal table but EF doesn't support unique keys yet.

Entity Framework Model Multiple Table to Single Entity

I've two tables named Modules and Privileges which are related by a foreign key relationship as shown below:
(source: baburajpb at sites.google.com)
I'd like to model Module and Privilege by adding ModuleName to Privilege. Later I'd be interested in creating a derived class (Menu in the illustration) from Privilege by adding a discriminating condition on ModuleName. Is this possible using Entity Framework?
Can you map multiple tables to a single entity type? Sure, that is supported. However, you cannot use a mapped field of the table (ModuleName) as a discriminator column for table per hierarchy mapping. The discriminator column must be used as a discriminator alone, and must not be mapped into your client schema.

Categories

Resources