Auto increment and default values in EntityFramework

Auto increment and default values in EntityFramework

Postby imre.dudas » Fri 26 Mar 2010 11:01

Hello,

How do I use AutoIncrement fields and default values in EntityFramework? If I create a new row, the auto increment Id field's default value is 0. I not found AutoIncrement properties in EntityDeveloper.

Regards:
Imre
imre.dudas
 
Posts: 18
Joined: Thu 11 Mar 2010 20:36

Postby AndreyR » Fri 26 Mar 2010 11:45

You should set the StoreGeneratedPattern attribute to "Identity" in the Store part of the model for the autoincrement property.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby imre.dudas » Fri 26 Mar 2010 19:12

AndreyR wrote:You should set the StoreGeneratedPattern attribute to "Identity" in the Store part of the model for the autoincrement property.


Ok, thank you. But if i set that you said, I got an exception.
I'm sorry, because i use DCSQLite in this project. Sorry again. :-)

So, I have a table, called Folders. In this table FolderId field is an Auto increment field.
My example code:
Folders nf = new Folders();
nf.FolderName = "test folder";
EnochDb.AddToForms(nf);
EnochDb.SaveChanges();

The line "savechanges" given an exception (there is exception after my post, because it's too long).
Also i got an exception, when i set FolderId by manualy before rows add and save.
When i don't set that you said, and set FolderId manualy, the savechanges method don't give an exception.

I found StoreGeneratedPattern at the tables and views/Folders/folder_id in EntityDeveloper.

Regards:
Imre
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Data.UpdateException: An error occurred while updating the entries. See the InnerException for details. ---> System.Data.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.NotImplementedException: ReturningSql is not supported
at Devart.Common.Entity.h.a(StringBuilder A_0, DbModificationCommandTree A_1, a A_2, DbExpression A_3, DbProviderManifest A_4)
at Devart.Common.Entity.h.a(DbInsertCommandTree A_0, DbCommand A_1, DbProviderManifest A_2)
at Devart.Data.SQLite.Entity.c.a(DbCommandTree A_0, DbConnection A_1, DbProviderManifest A_2)
at Devart.Data.SQLite.Entity.SQLiteEntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at Enoch2.Forms.EnochMain.CreateNewFolder(String FolderName, String FolderNote) in C:\Users\Dudás Imre\Documents\Visual Studio 2008\Projects\Enoch2\Enoch2\Forms\EnochMain.cs:line 86
at Enoch2.Forms.EnochMain.NewFolder_Click(Object sender, EventArgs e) in C:\Users\Dudás Imre\Documents\Visual Studio 2008\Projects\Enoch2\Enoch2\Forms\EnochMain.cs:line 95
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.ToolStripDropDownItem.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.ToolStrip.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.ToolStripDropDown.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
imre.dudas
 
Posts: 18
Joined: Thu 11 Mar 2010 20:36

Postby AndreyR » Mon 29 Mar 2010 12:04

Unfortunately, we have a particular problem with SQLite and StoreGeneratedPattern.
I will let you know as soon as it is fixed.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby AndreyR » Wed 31 Mar 2010 11:50

We have fixed the autoincrement problem in SQLite. The new build will contain the fix.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby imre.dudas » Wed 31 Mar 2010 14:43

AndreyR wrote:We have fixed the autoincrement problem in SQLite. The new build will contain the fix.


Thank you. You are working very fast. :-)
imre.dudas
 
Posts: 18
Joined: Thu 11 Mar 2010 20:36

Postby AndreyR » Wed 31 Mar 2010 15:02

The fixed build is available.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to dotConnect for PostgreSQL