Convert (1 to Many ) to (1 to 1) Casehttp://forums.asp.net/t/1794187.aspx/1?Convert+1+to+Many+to+1+to+1+CaseMon, 23 Apr 2012 01:24:38 -040017941874938571http://forums.asp.net/p/1794187/4938571.aspx/1?Convert+1+to+Many+to+1+to+1+CaseConvert (1 to Many ) to (1 to 1) Case <p>Hi, here is my case,</p> <p>I have two tables:</p> <p>1- <strong>Employee</strong> (ID, Number, Salary) ID is a primary identity key.</p> <p>2 -<strong>Language</strong> (ID,Name) ID is a primary identity&nbsp;key.</p> <p>2- <strong>EmployeeTranslation&nbsp;</strong>(EmployeeID, LanguageID, Name)&nbsp;EmployeeID &#43; LanguageID is a primary key, and&nbsp;EmployeeID is&nbsp;foreign key</p> <p>constraint to the <strong>Employee</strong> table for the ID column, and the&nbsp;LanguageID&nbsp;is&nbsp;foreign key&nbsp;constraint to the&nbsp;<strong>Language</strong> table&nbsp;for the ID</p> <p>column.</p> <p></p> <p>So these tables enables you to insert an employee row with multi translations rows (His name in english, french, japanese .. etc) .</p> <p>When i map this to the entity framework using database first model i will get an Employee entity with a relation to a many&nbsp;translation</p> <p>entities&nbsp;of type EmployeeTranslation (<strong>1 to Many</strong>), but what i really want is to map the Employee entity to one EmployeeTranslation&nbsp;</p> <p>entity (<strong>1 to 1</strong>), why,because the real business senario here is that i will <strong>only and always</strong> get an Employee Entity with one Translation</p> <p>Entity based on&nbsp;the system&nbsp;current language, How can i apply this in entity framework.</p> <p></p> <p>Note: When you convert the (1 to Many) relation in this senario to (1 to 1) you will get and error of course.&nbsp;</p> 2012-04-18T10:17:32-04:004938582http://forums.asp.net/p/1794187/4938582.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>If an Employee can only have one EmployeeTranslation and an EmployeTransaction only belongs to one Employee, you should remove the EmpoyeeTranslation table in your database and add the columns LanguageID and [Translation]Name to the Employee table. Then you will get a 1-to-1 relationsship. There is no need to have another table for that.</p> 2012-04-18T10:21:44-04:004938620http://forums.asp.net/p/1794187/4938620.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>The employee can have more than one translation in the data base tables but in the Domain layer (Business layer) i should get one</p> <p>for the current&nbsp;system language.&nbsp;</p> 2012-04-18T10:37:21-04:004938622http://forums.asp.net/p/1794187/4938622.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>If you for some reason wants to keep the EmployeeTranslation table, you should set the EmployeeID column as primary key and remove the foreign key between the Employee and EmployeeTranslation table.</p> 2012-04-18T10:38:45-04:004938636http://forums.asp.net/p/1794187/4938636.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p></p> <blockquote><span class="icon-blockquote"></span> <h4>matelin</h4> <p></p> <p>The employee can have more than one translation in the data base tables but in the Domain layer (Business layer) i should get one</p> <p>for the current&nbsp;system language.&nbsp;</p> <p></p> </blockquote> <p></p> <p>If you don't want your domain model to behave like your database model you can't excpect the database-first generated model to work without any modifications to it. Please see this article for an example of how to define a 1-to-1 relationsship in code: <a href="http://blog.bennymichielsen.be/2011/06/02/entity-framework-4-1-one-to-one-mapping/"> http://blog.bennymichielsen.be/2011/06/02/entity-framework-4-1-one-to-one-mapping/</a></p> 2012-04-18T10:46:53-04:004938643http://forums.asp.net/p/1794187/4938643.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p></p> <blockquote><span class="icon-blockquote"></span> <h4>mm10</h4> <p></p> <p>If you for some reason wants to keep the EmployeeTranslation table, you should set the EmployeeID column as primary key and remove the foreign key between the Employee and EmployeeTranslation table.</p> <p></p> </blockquote> <p></p> <p>I think this will road to an inconsistent mapping by removing the relation&nbsp;and an unwell designed relational database.</p> <p>Any other ideas.&nbsp;</p> 2012-04-18T10:48:36-04:004938665http://forums.asp.net/p/1794187/4938665.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p></p> <blockquote><span class="icon-blockquote"></span> <h4>matelin</h4> <p></p> <p>I think this will road to an inconsistent mapping by removing the relation&nbsp;and an unwell designed relational database.</p> <p></p> </blockquote> Yes, if the tables in your DB&nbsp;are to have a 1-to-many relationsship you cannot to this but if the relationsship is 1-to-1 you should do this. <p></p> 2012-04-18T10:58:36-04:004938722http://forums.asp.net/p/1794187/4938722.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>One of the reasons for what i want is that i already have a custom entity mapping implementation for that , but i want to implement</p> <p>this&nbsp;using entity framework&nbsp;so i can benefits&nbsp;from its features.</p> <p>And yes i know it will require an extra work ,for that iam asking for help,i will read more about code first model , i may have it done,</p> <p>i know&nbsp;a little about code first model ,but what iam afraid of the code first nodel is to lose the control over my database.&nbsp;</p> <p></p> <p>Any help will be appreciated</p> 2012-04-18T11:23:42-04:004941914http://forums.asp.net/p/1794187/4941914.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>Hello matelin</p> <p>As far as I seeI think since you want to make Employee(One)(One)EmployTranslationIn fact I think you can find a certain Employee to find out what language he/she is speaking nowSo there's no need for you to create EmployeeTranslationBut just do this</p> <p>Solutions</p> <p>Employee(Id,Number,Salary,LanguageId)Here LanguageId is a foreign key mapped to Language table</p> <p>Language(Id,LanguageName)Id the primary key</p> <p>Shorten the three tables into two</p> 2012-04-20T01:13:49-04:004944856http://forums.asp.net/p/1794187/4944856.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p>I can not do that, becuase the idea behind that is to allow the user to translate the text data like employee name to many laguages.</p> 2012-04-22T14:23:53-04:004945193http://forums.asp.net/p/1794187/4945193.aspx/1?Re+Convert+1+to+Many+to+1+to+1+CaseRe: Convert (1 to Many ) to (1 to 1) Case <p></p> <blockquote><span class="icon-blockquote"></span> <h4>matelin</h4> becuase the idea behind that is to allow the user to translate the text data like employee name to many laguages.</blockquote> <p></p> <p>Solutions</p> <p>Employee(Id,Name,Salary)Here only for Employees</p> <p>Language(Id,LanguageName)Here's only for Languages</p> <p>Translations(Id,EmployeeId,LauguageId)Here's a joint table for Employee and LanguageIn my mindYou should create a Many-To-Many relationship between the two tablesbecause One Employee can have multiple languagesand so you can find out all the languages belonging to a certain EmployeeAnd if one employee can only learn one languageyou can find only onefor &quot;One&quot; is a special thing for Many</p> <p>Reguards</p> 2012-04-23T01:24:38-04:00