This question is locked. New answers and comments are not allowed.

Elisabeth Ohmstead
Top achievements
Rank 1
Elisabeth Ohmstead
asked on 18 Apr 2013, 05:06 AM
Dear Sir or Madam,
I have been experiencing a strange behavior of the ORM. My code is as follows:
The line
I have been experiencing a strange behavior of the ORM. My code is as follows:
private
static
void
UpdateDatabase()
{
using
(var context =
new
EntitiesModel())
{
var schemaHandler = context.GetSchemaHandler();
EnsureDB(schemaHandler);
}
}
private
static
void
EnsureDB(ISchemaHandler schemaHandler)
{
string
script =
null
;
if
(schemaHandler.DatabaseExists())
{
script = schemaHandler.CreateUpdateDDLScript(
null
);
}
else
{
schemaHandler.CreateDatabase();
script = schemaHandler.CreateDDLScript();
}
if
(!
string
.IsNullOrEmpty(script))
{
schemaHandler.ExecuteDDLScript(script);
}
}
The line
script = schemaHandler.CreateUpdateDDLScript(
null
); always returns null and script = schemaHandler.CreateDDLScript(); always return an empty string.
I have tried to modify my database and delete it but the strange behavior still persists.
Please help me!5 Answers, 1 is accepted
0
Hi Elisabeth,
The reason why the method CreateUpdateDDLScript(null) returns null is because your model is up to date with your database and there is nothing to update.Please note that if there is no database with the specified name, the CreateDDLScript and the CreateUpdateDDLScript will not create it but instead they will throw an exception. Should you want to create the database you need to call the method CreateDatabase on the ISchemaHandler interface.
As for the exact definition of the CreateDDLScript and the CreateUpdateDDLScript please have a look into those descriptions:
CreateUpdateDDLScript - generates a migration data definition language (DDL) script. What this basically does is it generates an SQL script that will create only the missing parts based on a comparison between your metadata and your actual database.The method is expect to return null should your model match your database.
CreateDDLScript - generates a data definition language (DDL) script that creates schema objects (tables, primary keys, foreign keys) by using the metadata provided by the OpenAccessContext. This method does not take into consideration your current database state. Also it will return empty string if you don't have any classes in your model (the RLINQ file) with property UpdateSchema set to true.
Should you face any further difficulties please do not hesitate to contact us back.
Regards,
Yordan
the Telerik team
The reason why the method CreateUpdateDDLScript(null) returns null is because your model is up to date with your database and there is nothing to update.Please note that if there is no database with the specified name, the CreateDDLScript and the CreateUpdateDDLScript will not create it but instead they will throw an exception. Should you want to create the database you need to call the method CreateDatabase on the ISchemaHandler interface.
As for the exact definition of the CreateDDLScript and the CreateUpdateDDLScript please have a look into those descriptions:
CreateUpdateDDLScript - generates a migration data definition language (DDL) script. What this basically does is it generates an SQL script that will create only the missing parts based on a comparison between your metadata and your actual database.The method is expect to return null should your model match your database.
CreateDDLScript - generates a data definition language (DDL) script that creates schema objects (tables, primary keys, foreign keys) by using the metadata provided by the OpenAccessContext. This method does not take into consideration your current database state. Also it will return empty string if you don't have any classes in your model (the RLINQ file) with property UpdateSchema set to true.
Should you face any further difficulties please do not hesitate to contact us back.
Regards,
Yordan
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
0

Dave
Top achievements
Rank 1
answered on 14 May 2013, 07:07 PM
I must be missing something to - because when I run those commands above with a new database in the connectionstring - it errors at
As expected but when it falls to the next segment
It will create a blank database BUT CreateDDLScript returns an empty string, so it leaves me with an empty database.
Is there something I am missing?
script = handler.CreateUpdateDDLScript(Nothing)
As expected but when it falls to the next segment
Dim throwException As Boolean = False
Try
handler.CreateDatabase()
script = handler.CreateDDLScript()
Catch
throwException = True
End Try
If throwException Then
Throw
End If
It will create a blank database BUT CreateDDLScript returns an empty string, so it leaves me with an empty database.
Is there something I am missing?
0
Hello Dave,
Please ensure that every class that you want a table to be generated for, has the property UpdateSchema set to true. After setting this property to true the method CreateDDLScript should return a non empty string. That returned string should be passed to the method ExecuteDDLScript so the tables are created in the empty database. The complete code for creating the database is similar to the following:
Please try the suggested approach and if it doesn't work as expected get back to us.
Regards,
Yordan
the Telerik team
Please ensure that every class that you want a table to be generated for, has the property UpdateSchema set to true. After setting this property to true the method CreateDDLScript should return a non empty string. That returned string should be passed to the method ExecuteDDLScript so the tables are created in the empty database. The complete code for creating the database is similar to the following:
Public
Sub
UpdateSchema()
Dim
handler =
Me
.GetSchemaHandler()
Dim
script
As
String
=
Nothing
Try
script = handler.CreateUpdateDDLScript(
Nothing
)
Catch
Dim
throwException
As
Boolean
=
False
Try
handler.CreateDatabase()
script = handler.CreateDDLScript()
Catch
throwException =
True
End
Try
If
throwException
Then
Throw
End
If
End
Try
If
String
.IsNullOrEmpty(script) =
False
Then
handler.ExecuteDDLScript(script)
End
If
End
Sub
Please try the suggested approach and if it doesn't work as expected get back to us.
Regards,
Yordan
the Telerik team
OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
0

Jed
Top achievements
Rank 1
answered on 07 Sep 2014, 11:04 AM
Good day.
I'd like to ask the same question posted. When I tried to delete my database and then run my program with this code, It did create the database, but not the tables, etc.. What am I missing? What will I do?
Thanks.
private static void EnsureDB(ISchemaHandler schemaHandler)
{
string script = null;
if (schemaHandler.DatabaseExists())
{
script = schemaHandler.CreateUpdateDDLScript(null);
}
else
{
schemaHandler.CreateDatabase();
script = schemaHandler.CreateDDLScript();
}
if (!string.IsNullOrEmpty(script))
{
schemaHandler.ExecuteDDLScript(script);
}
}
I'd like to ask the same question posted. When I tried to delete my database and then run my program with this code, It did create the database, but not the tables, etc.. What am I missing? What will I do?
Thanks.
private static void EnsureDB(ISchemaHandler schemaHandler)
{
string script = null;
if (schemaHandler.DatabaseExists())
{
script = schemaHandler.CreateUpdateDDLScript(null);
}
else
{
schemaHandler.CreateDatabase();
script = schemaHandler.CreateDDLScript();
}
if (!string.IsNullOrEmpty(script))
{
schemaHandler.ExecuteDDLScript(script);
}
}
0
Hi Jed,
Please ensure that for every class that you want a table for, the 'UpdateSchema' property should set to 'true'. You can set this property via the domain model designer by selecting the class,pressing F4 and setting the value in the 'Properties' window.
Once this property is set the 'CreateUpdateDDLScript/CreateDDLScript' methods should generate the required DDL script.
Do let me know if that works and in case you need further assistance.
Regards,
Ady
Telerik
Please ensure that for every class that you want a table for, the 'UpdateSchema' property should set to 'true'. You can set this property via the domain model designer by selecting the class,pressing F4 and setting the value in the 'Properties' window.
Once this property is set the 'CreateUpdateDDLScript/CreateDDLScript' methods should generate the required DDL script.
Do let me know if that works and in case you need further assistance.
Regards,
Ady
Telerik
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.