General EntityDAC issues
Posted: Thu 06 Mar 2014 15:31
I am in the process of choosing an ORM for use in my company's applications. We use Delphi XE5 atm.
I am trying to set up a basic app with an SQLExpress db. As an experienced .net programmer, who is used to NHibernate, it is frustrating that the documentation is very lacking. It mostly explains how to do this by dropping Components into a form, not how to execute codebehind. Anyway, my specific issue is:
I have 2 classes, Person and Product. Both are autogenerated from Entity Developer.
My setup seems fine, as my database is created:
Now, I want to create a New person and insert it to my db. Followed instructions from the documentation:
However this fails at "Context.Attach(p)", with a memory access violation error. Stepped through this line by line; the person Object is created and the Properties filled, but it will not add it to the context. I have tried several approaches:
I have also tried setting the primary key (ID) of the person without effect, and anyway the ID is a db generated Identity seed.
Any ideas on where I go wrong here?
I am trying to set up a basic app with an SQLExpress db. As an experienced .net programmer, who is used to NHibernate, it is frustrating that the documentation is very lacking. It mostly explains how to do this by dropping Components into a form, not how to execute codebehind. Anyway, my specific issue is:
I have 2 classes, Person and Product. Both are autogenerated from Entity Developer.
My setup seems fine, as my database is created:
Code: Select all
Conn := TEntityConnection.Create(self);
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Initial Catalog=Test2;Data Source=.\SQLEXPRESS;User ID=sa;Password=xxx;';
Conn.DefaultModelName := 'TestModel';
Conn.ProviderName := 'ADO';
Conn.Dialect := 'SQL Server';
Conn.Connect;
Conn.CreateDatabase();
Code: Select all
Conn := TEntityConnection.Create(self);
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Initial Catalog=Test2;Data Source=.\SQLEXPRESS;User ID=sa;Password=xxx;';
Conn.DefaultModelName := 'TestModel';
Conn.ProviderName := 'ADO';
Conn.Dialect := 'SQL Server';
Conn.Connect;
Context:=TEntityContext.Create(self);
Context.ModelName:='TestModel';
Context.Connection:=Conn;
p:=TPerson.Create;
p.Name:='Bono Vox';
p.Email:='[email protected]';
p.Phone:='12345678';
Context.Attach(p);
p.Save;
Code: Select all
p.Attach(Context);
Code: Select all
p:= Context.CreateAttachedEntity(EmpType, 1);
Any ideas on where I go wrong here?