I'm getting an error when i want to update or delete an entity in a formview with the LLBLGenProDatasource2.
This is the error:
"There are no primary key fields specified in the bound control and/or the bound control didn't specify any primary key fields. Delete can't continue."
It seems the formview.DataKey.Value is null at the moment i want to perform the update / delete.
I'm working with the latest version of LLBLGen.
Here's some code:
<llblgenpro:LLBLGenProDataSource2 ID="ds" runat="server" MaxNumberOfItemsToReturn="1" DataContainerType="EntityCollection"
AdapterTypeName="Data.DatabaseSpecific.DataAccessAdapter, DataDBSpecific"
EntityFactoryTypeName="Data.FactoryClasses.RoleEntityFactory, Data"
LivePersistence="False" OnPerformSelect="ds_PerformSelect" OnPerformWork="ds_PerformWork">
</llblgenpro:LLBLGenProDataSource2>
<asp:FormView ID="fvRole" DataKeyNames="RoleId" runat="server" DataSourceID="ds" CellPadding="0" Width="100%">
<InsertItemTemplate>
...
</InsertItemTemplate>
<EditItemTemplate>
<table style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px;
width: 100%; border-top-style: none; padding-top: 0px; border-right-style: none;
border-left-style: none; border-bottom-style: none" cellspacing="0" cellpadding="2">
<tr>
<td style="width: 140px">
<tdit:tdASPxLabel runat="server" Text="Nummer" ID="lblRoleNumber" TranslationProperty="Text"
TabIndex="0" TranslationTag="fieldRoleNumber:">
</tdit:tdASPxLabel>
</td>
<td>
<tdit:tdTextBox runat="server" Height="16px" CssClass="input" Width="100%" ID="txtRoleNumber"
TabIndex="0" RightsProperty="CheckForUpdate" Text='<%# Bind("RoleNumber") %>'>
</tdit:tdTextBox>
</td>
</tr>
<tr>
<td style="width: 140px">
<tdit:tdASPxLabel runat="server" Text="Naam" ID="lblRoleName" TranslationProperty="Text"
TabIndex="0" TranslationTag="fieldRoleName:">
</tdit:tdASPxLabel>
</td>
<td>
<tdit:tdTextBox runat="server" Height="16px" CssClass="input" Width="100%" ID="txtRoleName"
TabIndex="0" RightsProperty="CheckForUpdate" Text='<%# Bind("RoleName") %>'>
</tdit:tdTextBox>
</td>
</tr>
<tr>
<td style="width: 140px">
<tdit:tdASPxLabel runat="server" Text="Verkorte naam" ID="lblRoleNameShort" TranslationProperty="Text"
TabIndex="0" TranslationTag="fieldRoleNameShort:">
</tdit:tdASPxLabel>
</td>
<td>
<tdit:tdTextBox runat="server" Height="16px" CssClass="input" Width="100%" ID="txtRoleNameShort"
TabIndex="0" RightsProperty="CheckForUpdate" Text='<%# Bind("RoleNameShort") %>'>
</tdit:tdTextBox>
</td>
</tr>
<tr>
<td style="width: 140px">
</td>
<td>
<asp:Label runat="server" ID="txtRoleId" Text='<%# Bind("RoleId") %>'></asp:Label>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
And this is my code behind:
protected void ds_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
try
{
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath, e.PageNumber, e.PageSize);
}
}
catch (Exception ex)
{
Globals.logger.LogError(ex);
}
}
protected void ds_PerformWork(object sender, PerformWorkEventArgs2 e)
{
try
{
List<UnitOfWorkElement2> elementsToInsert = e.Uow.GetEntityElementsToInsert();
if (elementsToInsert.Count > 0)
{
((RoleEntity)elementsToInsert[0].Entity).CompanyId = Globals.config.CompanyId;
}
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
e.Uow.Commit(adapter, true);
}
}
catch (Exception ex)
{
Globals.logger.LogError(ex);
}
}
protected override void BaseEntityPage_ToolBarDeleteClicked()
{
base.BaseEntityPage_ToolBarDeleteClicked();
try
{
if (!this.NewEntity)
{
fvRole.DeleteItem();
}
Response.Redirect("RightsAndRoles.aspx");
}
catch (Exception ex)
{
Globals.logger.LogError(ex);
}
}
Same for update, but with fvRole.UpdateItem(bool);
I hope someone can help me with this problem.