Entity Mapping

Entity Mapping

Postby rodrigobarbosa » Wed 08 Jun 2016 13:28

Hi,

I've been following the documentaiton found in the https://www.devart.com/entitydac/docs/?first_app_express.htm and making a framework for my company internal usage.

Basically, i have to create entity throught out code. But my mapping end up with runtime error and i'm clueless why. It only happens when an entity has more than one reference or collection.

this one is ok
Code: Select all
[Table('enum')]
[Model('DataModel')]
[Key('Fenumid')]
TCAFEnum = class(TMappedEntity)
private
  [Column('enumid', [ReadOnly])]
  Fenumid: Integer;

  [Column]
  [Collection('TCAFEnumItem', 'FCAFEnum', 'Fenumitemid', 'Fenumitemid', srNone, drNone)]
  FCAFEnumItemCollection: TCollectionData;
...
end;

[Table('enumitem')]
[Model('DataModel')]
[Key('Fenumitemid')]
TCAFEnumItem = class(TMappedEntity)
private
  [Column('enumitemid', [ReadOnly])]
  Fenumitemid: Integer;
  [Column('enumid', [CanBeNull])]
  Fenumid: IntegerNullable;

  [Column]
  [Reference('TCAFEnum','FCAFEnumItemCollection','Fenumid','Fenumid', srNone,drNone)]
  FCAFEnum: TReferenceData;

...
end;


However, when i add another reference it gives me a Runtime error 217 .....
Code: Select all
[Table('project')]
[Model('DataModel')]
[Key('Fprojectid')]
TCAFProject = class(TMappedEntity)
private
  [Column('projectid', [ReadOnly])]
  Fprojectid: Integer;

  [Column]
  [Collection('TCAFEnum', 'FCAFProject', 'Fprojectid', 'Fprojectid', srNone, drNone)]
  FCAFEnumCollection: TCollectionData;

...
end;

[Table('enum')]
[Model('DataModel')]
[Key('Fenumid')]
TCAFEnum = class(TMappedEntity)
private
  [Column('enumid', [ReadOnly])]
  Fenumid: Integer;

  [Column]
  [Reference('TCAFProject', 'FCAFEnumCollection', 'Fprojectid', 'Fprojectid', srNone, drNone)]
  FCAFProject: TReferenceData;

  [Column]
  [Collection('TCAFEnumItem', 'FCAFEnum', 'Fenumitemid', 'Fenumitemid', srNone, drNone)]
  FCAFEnumItemCollection: TCollectionData;
...
end;

[Table('enumitem')]
[Model('DataModel')]
[Key('Fenumitemid')]
TCAFEnumItem = class(TMappedEntity)
private
  [Column('enumitemid', [ReadOnly])]
  Fenumitemid: Integer;
  [Column('enumid', [CanBeNull])]
  Fenumid: IntegerNullable;

  [Column]
  [Reference('TCAFEnum','FCAFEnumItemCollection','Fenumid','Fenumid', srNone,drNone)]
  FCAFEnum: TReferenceData;

...
end;


Any help is appreciated



I got the solution,
i was mistaking the reference ID, plus it is case sensitive.
rodrigobarbosa
 
Posts: 7
Joined: Fri 11 Mar 2016 13:25
Location: Curitiba, Brazil

Re: Entity Mapping

Postby AlexP » Tue 14 Jun 2016 09:52

Glad to see that you have found the solution. If you have any other questions, feel free to contact us
AlexP
Devart Team
 
Posts: 5525
Joined: Tue 10 Aug 2010 11:35


Return to EntityDAC