Delphy XE7 - EntityTable append record when field is AutoInc, missing refresh field value
Posted: Thu 15 Jan 2015 16:03
Hi,
In a simple MSSQL table designed and generated using Entity Developer v5.7.451 with two fields :
CREATE TABLE dbo.Inventory (
InventoryId INT NOT NULL IDENTITY,
InventoryDescription NVARCHAR(120),
CONSTRAINT PK_Inventory PRIMARY KEY (InventoryId)
)
I insert some records and work ok in Management Studio.
Then, in Delphi XE7, using the following EntityConnection, EntityTable, and EntityDataSource components:
object mainConnection: TEntityConnection
LoginPrompt = False
ConnectionString =
'Data Provider=SDAC;SQL Dialect=SQL Server;Login Prompt=False;Ser' +
'ver=DEVELOP\SQLEXPRESS;Database=DataInventory;Integrated Se' +
'curity=True'
ProviderName = 'SDAC'
DialectName = 'SQL Server'
DefaultModelName = 'DataInventoryModel'
end
(of course, I'd included EntityXMLModel, SDACDataProvider and EntityContext and configured them)
object dsInventory: TEntityDataSource
AutoEdit = False
DataSet = entityInventory
Left = 144
Top = 272
end
object entityInventory: TEntityTable
FieldExpressions = <>
Context = EntityContext1
TypeName = 'Inventory'
object entityInventoryInventoryId: TIntegerField
AutoGenerateValue = arAutoInc
FieldName = 'InventoryId'
end
object entityInventoryDescription: TStringField
FieldName = 'InventoryDescription'
Size = 120
end
end
Then I bind those fields to a simple TListView (with Text to InventoryDescription, and Detail to InventoryId)
And a TEdit binded to InventoryDescription and a TBindNavigator binded to the TDataSource
Looks great! It shows all records previously added on Management Studio with both fields very well.
The problem is when I insert a new record, it goes to the Database and data is saved correctly.
But, it seem do not refresh the InventoryId field with new value. Then it shows 0 in Detail.
When I try to create a new one, there is an error:
Inserting error: "List does not allow duplicates ($0%x)"
And when I update same new field, then, new changes don't go to Database.
I think: Of course!, inside entityTable there is no InventoryId updated with new value.
Can you help me? What am I missing?
Thanks
Abner
In a simple MSSQL table designed and generated using Entity Developer v5.7.451 with two fields :
CREATE TABLE dbo.Inventory (
InventoryId INT NOT NULL IDENTITY,
InventoryDescription NVARCHAR(120),
CONSTRAINT PK_Inventory PRIMARY KEY (InventoryId)
)
I insert some records and work ok in Management Studio.
Then, in Delphi XE7, using the following EntityConnection, EntityTable, and EntityDataSource components:
object mainConnection: TEntityConnection
LoginPrompt = False
ConnectionString =
'Data Provider=SDAC;SQL Dialect=SQL Server;Login Prompt=False;Ser' +
'ver=DEVELOP\SQLEXPRESS;Database=DataInventory;Integrated Se' +
'curity=True'
ProviderName = 'SDAC'
DialectName = 'SQL Server'
DefaultModelName = 'DataInventoryModel'
end
(of course, I'd included EntityXMLModel, SDACDataProvider and EntityContext and configured them)
object dsInventory: TEntityDataSource
AutoEdit = False
DataSet = entityInventory
Left = 144
Top = 272
end
object entityInventory: TEntityTable
FieldExpressions = <>
Context = EntityContext1
TypeName = 'Inventory'
object entityInventoryInventoryId: TIntegerField
AutoGenerateValue = arAutoInc
FieldName = 'InventoryId'
end
object entityInventoryDescription: TStringField
FieldName = 'InventoryDescription'
Size = 120
end
end
Then I bind those fields to a simple TListView (with Text to InventoryDescription, and Detail to InventoryId)
And a TEdit binded to InventoryDescription and a TBindNavigator binded to the TDataSource
Looks great! It shows all records previously added on Management Studio with both fields very well.
The problem is when I insert a new record, it goes to the Database and data is saved correctly.
But, it seem do not refresh the InventoryId field with new value. Then it shows 0 in Detail.
When I try to create a new one, there is an error:
Inserting error: "List does not allow duplicates ($0%x)"
And when I update same new field, then, new changes don't go to Database.
I think: Of course!, inside entityTable there is no InventoryId updated with new value.
Can you help me? What am I missing?
Thanks
Abner