Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to create an association between two normal fields in Entity Framework, thereby ignoring the primary key?
    text
    copied!<p>I have the following situation between these three tables:</p> <p><img src="https://i.stack.imgur.com/D8IAJ.png" alt="alt text"></p> <p>Before I start explaining what I'm trying to accomplish here, let me clarify three things:</p> <ol> <li><p>I drew the model on EntityFramework, but this is actually the database view. Just assume that the fields type match between tables;</p></li> <li><p>I know that this database model sucks. But changing it is out of question. I know that it would make my life easier.</p></li> <li><p>I'm using Visual Studio 2008 and .Net 3.5 on this project. But I'm accepting solutions based on Visual Studio 2010 and .Net 4.0 as well.</p></li> </ol> <p>So, as I tried to demonstrate on the picture above, in this project that I'm working on I got these 3 tables. One of then, <strong>TransactionLine</strong>, associates a file to a transaction line, that is part of a full transaction.</p> <p>Now, what I'm trying to associate here is <strong>TransactionLine</strong> and <strong>File</strong>. However, <strong>TransactionLine</strong> doens't have <em>FileId</em> field from the <strong>File</strong> table. The fields <em>FileNumber</em> and <em>FileType</em> from this table stand for an composite key on <strong>File</strong>. And indeed, <strong>File</strong>'s <em>FileNumber</em> and <em>FileType</em> never repeat. They could be the primary key, but then again, I can't touch the database structure.</p> <p>I try to associate <strong>TransactionLine</strong> and <strong>File</strong> by creanting an <em>Association</em> of One To Many From <strong>File</strong> to <strong>TransactionLine</strong>. After that, I select the <em>Association</em> and change to the <em>Mapping Details</em> screen, then I select <em>Map's to</em> <strong><em>TransactionLine</em></strong>.</p> <p>The data that he askes me to fill on the model screen are:</p> <ul> <li><strong>File</strong>.<em>FileId</em>;</li> <li><strong>TransactionLine</strong>.<em>TransactionId</em>;</li> <li><strong>TransactionLine</strong>.<em>FileNumber</em>;</li> <li><strong>TransactionLine</strong>.<em>FileType</em>,</li> </ul> <p>All of the <strong>TransactionLine</strong> scalar properties are set by theirs corresponding database fields, which are of the same name. But when I'm going to specify the linkage with <strong>File</strong> table, the only scalar field that I can specify there is <em>FileId</em>, which I don't have on the <strong>TransactionLine</strong> table.</p> <p>I also tried to set <strong>File</strong>'s <em>FileNumber</em> and <em>FileType</em> scalar properties entity key flag to true, and <em>FileId</em> entity flag to false, but with no success, since the program warns me that database <em>FileId</em> is a primary key but is not set like one on the entity.</p> <p>Is it possible to link <strong>TransactionLine</strong> <em>FileNumber</em> and <em>FileType</em> with <strong>File</strong>? Is there any workaround for this situation?</p> <p>Special Note: <em>FileId</em> is indeed the primary key for <strong>File</strong>. Others tables link with it by this field. The <strong>TransactionLine</strong> here is an exception to the common sense rule. :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload