Page 1 of 1
EF4 POCO & Devart
Posted: Wed 07 Apr 2010 13:33
by Alladin
Hello there,
I'm trying to engage new feature of EF4 called code-only configuration.
Using ContextBuilder class from Microsoft.Data.Entity.CTP assembly.
However ObjectContext produced by ContextBuilder.Create with OracleCommand as connection, produces MSSQL-based context.
So my all selects look like this:
Code: Select all
SELECT
"Extent1"."courseid" AS "courseid",
"Extent1"."price" AS "price",
"Extent1"."title" AS "title"
FROM "dbo"."course" "Extent1"
What am I doing wrong or does DevArt EF4 provider support EF4 code-only configuration?
PS. To moderator, could you please move this post to Entity Framework forum?
Posted: Thu 08 Apr 2010 13:48
by AndreyR
We are investigating the situation.
I will let you know about the results.
Posted: Thu 15 Apr 2010 08:03
by ghostknight
The "dbo" issue is on the EF4 side. I've described it here
http://social.msdn.microsoft.com/Forums ... d55f890d61
They promise to fix it before release.
And enclosing identifiers in quotes is definitely dotConnect's issue
I've posted investigation here:
http://www.devart.com/forums/viewtopic. ... 5665#55665
Posted: Fri 16 Apr 2010 09:51
by AndreyR
The Code Only functionality was not added into Entity Framework v4 RTM.
Existing EF CTP 3 works with EF v4 RTM but has some known compatibility issues, for example some DB Generation issues, table mapping customization problems, the "dbo" bug etc.
However, we have found a workaround for the problems like the one you've encountered. First we are creating a custom MyTable class:
Code: Select all
public class MyTable {
public int Id { get; set; }
public string F_String { get; set; }
}
Here is the usage example:
Code: Select all
var builder = new ContextBuilder();
builder.Entity()
.HasKey(a => a.Id)
.MapSingleType(a => new {
ID = a.Id,
F_STRING = a.F_String
})
.ToTable("SCOTT.MY_TABLE");
OracleConnection con = new OracleConnection("User Id=scott;Password=tiger;Server=ORA;");
ObjectContext context = builder.Create(con);
ObjectSet MyTables = context.CreateObjectSet();
var allMyTablesQuery = from it in MyTables
where it.Id < 10
orderby it.Id
select it;
string sql = (allMyTablesQuery as ObjectQuery).ToTraceString();
The SQL generated:
Code: Select all
SELECT
"Extent1".F_STRING AS F_STRING,
"Extent1".ID AS ID
FROM SCOTT.MY_TABLE "Extent1"
WHERE "Extent1".ID < 10
ORDER BY "Extent1".ID ASC
Posted: Fri 16 Apr 2010 11:07
by ghostknight
Great! Thanks, will try it... I've also foun another solution, but it doesn't go for production, only suiteable for testing|investigation purposes...
I'll try your solutuion.
Thanks a lot again!
Posted: Tue 15 Jun 2010 12:00
by Alladin
Does not work.
If you specify ToTable("nitro.TPORTFOLIOS"), insert SQL generated looks like this:
insert into "nitro".TPORTFOLIOS("Active", "ClosingTime", "clsid", "CreationTime", "Definition", "Description", "Id", "Name", "parent", "PublicId", "Tsid", "Type")
values (:p0, null, :p1, null, null, :p2, :p3, :p4, null, null, :p5, :p6)
Schema name is NITRO.
"ORA-00942: table or view does not exist"
To fix this problem, in generate SQL devart should:
1) Remove quotes in schema name (at least, or eliminate default dbo prefix).
2) Remove quotes in column names.
Posted: Wed 23 Jun 2010 09:22
by AndreyR
Please try to use the correct schema name, like here:
As for the column names, please try to specify the column names in the correct case in your model, mapping is appropriate to the names of your properties.
Posted: Tue 20 Jul 2010 13:55
by ChrisD
Hello,
I'm currently evaluating Code First (CTP 4) with POCO-classes for a project. In combination with Microsoft SQL Server, it works like a charm.
To connect to a local MySQL-server (v5.5.5 m3) I'd like to use the current dotConnect for MySQL to create the database scheme from my model. With CreateDatabaseScript(), I only get the "Creating all foreign keys" part in the DDL-script.
For example:
Code: Select all
ALTER TABLE dbo.DeviceConfigurations
ADD CONSTRAINT FK_DeviceConfiguration_Device FOREIGN KEY (DeviceId) REFERENCES dbo.Devices (DeviceId)
ON DELETE CASCADE ON UPDATE NO ACTION;
In general I can understand when there's not a total support for the unfinished Code First feature yet. But shouldn't the CreateDatabase-methods use the MetadataWorkspace-part of the Entity Framework to create the DDL-script?
Looking at the entries in the StoreItemCollection of the SSpace I don't see any difference between the configuration comparing code-based and model-based.
Thank you for time,
Christian
Posted: Fri 23 Jul 2010 10:53
by AndreyR
We are in the process of CTP 4 testing.
Could you please specify the message of the error you have encountered?
Posted: Fri 23 Jul 2010 13:50
by ChrisD
The initial error is a MySqlException (Table 'dbo.deviceconfigurations' doesn't exist) when trying to call CreateDatabase() on my model-instance.
This is perfectly clear when we consider the string that I'll get from CreateDatabaseScript() that is applied when using CreateDatabase() (see above).
Because there is only the constraint-definition in the script, the expected tables (in this case 'deviceconfigurations') have not been created beforehand, therefore causing this exception.
I've rechecked the Meta-information of the model and the entity-definitions for the tables are present (probably identical to model first). That's why I'm wondering if the Meta-information is wrongly presented with the new CTP4 or the script-creation in general is faulty.
ChrisD
Posted: Mon 26 Jul 2010 14:25
by AndreyR
Thank you for the information. Our testing is in progress, I will post here about the results.