Hi,
from my old post.
How do I manage the fields in entities used for foreign keys? I need them to serialize/deserialize and read the values for calculations, but those fields don't appear in the generated entities.
In their place there is the detail or related class, but there is no the true field with its value.
Thanks
Can you please better elaborate your question so we can fully understand what is the issue?
Please provide steps to reproduce the issue.
Well,
OK, let's take an example.
If I have this table in the database, which also has CountryID among its fields, related to the Country table. The generated entity has the below structure:
But where did CountryID go? If I need to use it for other purposes, display it, or reassign it for other purposes, where do I find it? If I need to serialize the entity's properties, I don't have that value, but the related class (Country). Why is it missing from the entity, if I actually need it for other uses o scopes, , besides the relationship with the Country entity?
I hope I was clear with my poor English :-)
Entity,Automapping
TCustomer = class
strict private
FId: integer;
FName: string;
FTitle: string;
FBirthday: TDateTime;
FCountry: TCountry;
public
property Id: Integer read FId write FId;
property Name: string read FName write FName;
property Title: string read FTitle write FTitle;
property Birthday: TDateTime read FDateTime write FDateTime;
property Country: TCountry read FCountry write FCountry;
end;
Country id is available through property Country and then its property Id:
CountryId := Customer.Country.Id;
Okay, I agree.
But if I need to perform serialization, deserialization, consistency checks, or value equality checks AUTOMATICALLY, I don't have all the values in the database that correspond to the entity's "linear" values, excluding related classes.
So I'm missing all the fields that are relationship keys.
Clearly, my exception concerns direct operations on entities for "parallel" management to that performed by Aurelius itself.
Question: if I manually implement these original fields in the classes (for now), will we encounter any problems? Are they normally set or managed from Aurelius?
Thanks
If you mean mapping CountryID database column to Integer field instead of TCountry, it's possible. But you will lose the Aurelius mechanism of doing joins and retrieving all the associated columns from Country table (and any other foreign key table).
You can also declare all associations are Proxy<T> and which that you have direct access to the foreign key values using Proxy.Key, as explained here: How Load, Proxy<T>.Key
Hi Wagner,
If you mean mapping CountryID database column to Integer field >instead of TCountry, it's possible. But you will lose the Aurelius >mechanism of doing joins and retrieving all the associated columns >from Country table (and any other foreign key table).
NO, I intend to have BOTH CountryID (Integer) AND TCountry, because I need to "read" all real fields connected with DB table fields.
What do you think?
Use the mentioned Proxy<T> approach.