Assertion fail

Discussion of open issues, suggestions and bugs regarding EntityDAC
Post Reply
jan.drozen
Posts: 3
Joined: Mon 23 Feb 2015 15:15

Assertion fail

Post by jan.drozen » Mon 23 Feb 2015 15:23

Hello,
we are looking for some ORM framework and we are considering to use EntityDAC. So I downloaded and installed the trial version to test some features. I wrote a very simple example:

Code: Select all

unit entityDACtest;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  EntityDAC.Entity,
  EntityDAC.EntityConnection,
  EntityDAC.EntityAttributes,
  EntityDAC.EntityContext,
  EntityDAC.DataProvider.FireDAC,
  EntityDAC.MetaEntity,
  EntityDAC.NullableTypes,
  EntityDAC.Types,
  EntityDAC.Utils,
  FireDAC.Stan.Def,
  FireDAC.Phys.MSSQL,
  FireDAC.DApt,
  FireDAC.VCLUI.Wait,
  FireDAC.Stan.Async;

type

	[Table('dbo.GTW_WORKFLOWS')]
  [Model('WorkflowModel')]
  [Key('FWorkflowid')]
  TGTWWorkflow = class(TMappedEntity)
  private
    [Column('workflowid')]
    FWorkflowid: Integer;
    [Column('typeid')]
    FTypeid: Integer;
    [Column('WF_name', 255, [CanBeNull])]
    FWfName: String;
  end;
  TForm1 = class(TForm)
    procedure onCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.onCreate(Sender: TObject);
var
	Lconnection: TEntityConnection;
  Lcontext: TEntityContext;
  Lworkflows: IEntityEnumerable<TGTWWorkflow>;
  Lworkflow : TGTWWorkflow;
begin
	Lconnection := TEntityConnection.Create;
  Lconnection.ProviderName := 'FireDAC';
  Lconnection.DialectName := 'SQL Server';
  Lconnection.ConnectionString := 'Data Provider=FireDAC;SQL Dialect=SQL Server;Login Prompt=False;DriverID=MSSQL;Server=127.0.0.1;Database=GTWtest;User_name=sa;Password=*********';
  Lconnection.Connect;
  Lcontext := TEntityContext.Create;
  Lcontext.Connection := Lconnection;
  Lcontext.ModelName := 'WorkflowModel';

   Lworkflows := Lcontext.GetEntities<TGTWWorkflow>;
   for Lworkflow in Lworkflows do
   begin
      ShowMessage(Lworkflow.FWfName);
   end;

end;

initialization

  ForceRtti(TGTWWorkflow);

end.
When calling the Lcontext.GetEntities<> the program crashes on assertion failure:

---------------------------
Debugger Exception Notification
---------------------------
Project entityDACproj.exe raised exception class EAssertionFailed with message 'Assertion failure (D:\Projects\Delphi\EntityDac\Source\EntityDAC.Entity.pas, line 319)'.
---------------------------
Break Continue Help
---------------------------

I'm a bit confused since there is no such path in my computer (there is not a drive D).
Can you please give me a way how to repair this example to working state?

Lot of thanks.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion fail

Post by AlexP » Tue 24 Feb 2015 12:24

Hello,

This occurs, because you haven't redefined your class constructor. You can find a constructor sample in the documentation: http://www.devart.com/entitydac/docs/democlassespas.htm .

jan.drozen
Posts: 3
Joined: Mon 23 Feb 2015 15:15

Re: Assertion fail

Post by jan.drozen » Thu 26 Feb 2015 15:12

Hello Alex,
thank you for your solution. It has worked after some additional fixes.
Can you please refer to any other point in documentation or reference, where is stated how and why is needed to redefine the ctors?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion fail

Post by AlexP » Mon 02 Mar 2015 10:42

See information about the TMappedEntity class constructor at http://www.devart.com/entitydac/docs/de ... create.htm .

Post Reply