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?