This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
When we drag a table with a foreign key column which is not a part of a primary key, the FK column doesn't appear in the designer nor in .cs file. Is it a designer bug? Can this column be added manually (directly in .cs file)? If yes, could you give us an example of code to add? |
|
|
DB is Oracle.
|
|
|
No, the foreign key column does not appear by design. Instead, an association is generated, which includes the FK field mapping. If the other end of the association is not yet part of the model, the association will be generated when you add the table at the other end of the association. Alternatively, if you just want the FK column without the association, add the XxxId property manually, either through the designer or in a partial class. Let us know if this is what you want and I will post an example. (Don't edit the generated .cs file directly: it will just get overwritten.) |
|
|
We have to be able to insert new records and set that field to a certain value in code. Our FK column name is ColFK.
DatabaseModelUnitOfWork unit = Repository.Context.CreateUnitOfWork(); OurTable izvodiBatchLog = new OurTable (); izvodiBatchLog.Col1= "some value"; izvodiBatchLog.Col2= "some value"; izvodiBatchLog.ColFK= 12; unit.Add(izvodiBatchLog); unit.SaveChanges();
|
|
|
To do this you have two options, depending on whether you want to model the association or whether you want to treat the FK value as an external magic number (needless to say, we recommend the former). If you want to model the association, create a one-to-many association from the associated thing to OurTable. This will generate two properties: AssociatedThing and AssociatedThingId. Now set the Column Name of the association to ColFK (the FK name in the database). You can now write izvodiBatchLog.AssociatedThingId = 12 and that will set the ColFK column. Alternatively, just drag the associated table onto the designer. The designer will spot that there is an association and do all this for you. If you want to treat the FK value as a plain old integer, just manually create a property called ColFK (right-click and choose Add Entity Property) of the appropriate type and nullability. |
|