SaveChanges() fails after implementing IDataSourceKeyResolver
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1010
Printed Date: 28-Apr-2026 at 1:42am
Topic: SaveChanges() fails after implementing IDataSourceKeyResolver
Posted By: dkearney1
Subject: SaveChanges() fails after implementing IDataSourceKeyResolver
Date Posted: 28-Nov-2008 at 5:27pm
I have used your Classic product for almost 2 years now. I'm currently working on a project using the EF product.
I'm trying to implement IDataSourceKeyResolver, but I'm getting a strange result. My code, without the key resolver, retrieves an entity from the database, modifies a few properties, saves the changes, and using a new instance of the DomainModelEntityManager re-retrieves the entity and verifies that the properties were modified. This works as expected.
When I implement IDataSourceKeyResolver, I successfully retrieve the entity, modify the values, and call SaveChanges, which appears to work, but doesn't actually save the changes to the database. Both the DebugLog.Xml and SQL Query Profiler confirm that no attempt to save was made. But the call to SaveChanges() returns with SaveResult.Ok. The code that re-retrieves the entity confirms that the changes were not applied.
What's going on?
Dan
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Replies:
Posted By: dkearney1
Date Posted: 28-Nov-2008 at 6:30pm
OK, maybe I'm just being dense. I moved my implementations out of the AppHelper assembly and into the ServerModel assembly, and they seem to be working fine.
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Posted By: dkearney1
Date Posted: 28-Nov-2008 at 7:22pm
After more testing, no, moving the implementation into the ServerModel assembly didn't help after all. So the original issue stands, after implementing IDataSourceKeyResolver I can no longer save entities, but I can fetch them just fine.
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Posted By: davidklitzke
Date Posted: 01-Dec-2008 at 8:46am
|
Dan,
Can you post your app.config and DebugLog.Xml files or send them to mailto:support@ideablade.com - support@ideablade.com ?
David
|
Posted By: dkearney1
Date Posted: 01-Dec-2008 at 8:49am
Yes, will do this evening.
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Posted By: dkearney1
Date Posted: 01-Dec-2008 at 4:24pm
|
I've posted the requested files from both a successful run and from a failed run. I modified the app.config files, removing the credentials, but made no other changes. I'm not sure if it's important, but the app.config file did not change between runs, as my implementation of IEntityLoginManager is also in the ServerModel assembly.
---- SUCCESSFUL EXAMPLE
-------- app.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="ideaBlade.v4" type="IdeaBlade.Util.Configuration.v4.IdeaBladeSection, IdeaBlade.Util.v4, Version=4.2.1.6, Culture=neutral, PublicKeyToken=287b5094865421c0" /> </configSections> <ideaBlade.v4 version="4.00" useDTC="false" copyLocal="false" loginManagerRequired="false" clientApplicationType="Standard" testMode="false"> <probeAssemblyNames> <probeAssemblyName name="ServerModel" /> </probeAssemblyNames> <logging logFile="DebugLog.xml" archiveLogs="false" serviceName="" port="0" usesSeparateAppDomain="false" /> <objectServer isDistributed="false" remoteBaseURL=" http://localhost - http://localhost " serviceName="EntityService" serverPort="9009" proxyName="" proxyPort="0" sessionEncryptionKey="" /> <edmKeys> <edmKey connection="metadata=res://ServerModel/ServerModel.csdl|res://ServerModel/ServerModel.ssdl|res://ServerModel/ServerModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=BOTS;User ID=--------;Password=--------;Packet Size=8192;MultipleActiveResultSets=True"" containerName="ServerModel.ServerModelContext" logTraceString="true" name="Default" tag=""> <probeAssemblyNames> <probeAssemblyName name="DomainModel" /> <probeAssemblyName name="ServerModel" /> </probeAssemblyNames> </edmKey> </edmKeys> <notificationService enabled="false" serverPort="9010" clientPort="0" /> </ideaBlade.v4> </configuration>
-------- debuglog.xml
<?xml version="1.0"?><?xml:stylesheet href="DebugLog.xsl" type="text/xsl"?><log> <entry id="0" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFileXmlLogger:GetLogHeader">------------ Log Created ------------</entry> <entry id="1" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: app.config embedded in Assembly: AppHelper Tester, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - not found</entry> <entry id="2" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: app.config embedded in Assembly: AppHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f8d11d1c794cd11 - found</entry> <entry id="3" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: Logging file: C:\Documents and Settings\Dan\My Documents\~Dev\BOTS\bin\DebugLog.xml</entry> <entry id="4" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">Bound to .NET runtime version 2.0.50727.3053</entry> <entry id="5" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">DevForce version 4.2.1.6</entry> <entry id="6" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.Util.v4.AuthHelper:LoadRuntimeLicense">IdeaBlade License: 'ProfessionalEF', KeyDate: 10/16/2008, AllowedSessions: 10000. Found on Assembly: 'DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f8d11d1c794cd11'</entry> <entry id="7" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.EntityModel.v4.EntityServerProxy:CreateInstance">Loaded IdeaBlade.EntityModel.v4.EntityServerProxy</entry> <entry id="8" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.EntityModel.v4.EntityServiceApplication:OnServiceStartup">EntityService created</entry> <entry id="9" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.EntityModel.v4.EntityService:get_LocalInstance">Created local EntityService</entry> <entry id="10" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.EntityModel.Server.v4.EntityServer:.ctor">EntityServer created for DataSourceExtension: Local</entry> <entry id="11" timestamp="2008-12-01T18:05:36" username="" source="IdeaBlade.EntityModel.Server.v4.SessionManager:GetLoginManager">Probed for 'IEntityLoginManager' and found SeverModel.LoginManager</entry> <entry id="12" timestamp="2008-12-01T18:05:38" username="BOTSAdmin" source="IdeaBlade.EntityModel.v4.IdGeneratorFactory:GetIdGenerator">Probed for 'IIdentityIdGenerator' and found IdeaBlade.EntityModel.v4.StoreGeneratedIdGenerator</entry> <entry id="13" timestamp="2008-12-01T18:05:38" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerFetching</entry> <entry id="14" timestamp="2008-12-01T18:05:38" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:Fetch">Fetch ... value(IdeaBlade.EntityModel.v4.EntityGroupProxy`1[DomainModel.BOTSUser]).OfType().Where(newObj => (newObj.Login = "BOTSAdmin")).Select(newObj => newObj).FirstOrDefault()</entry> <entry id="15" timestamp="2008-12-01T18:05:38" username="BOTSAdmin" source="IdeaBlade.EntityModel.v4.IdGeneratorFactory:GetIdGenerator">Probed for 'IIdentityIdGenerator' and found IdeaBlade.EntityModel.v4.StoreGeneratedIdGenerator</entry> <entry id="16" timestamp="2008-12-01T18:05:47" username="BOTSAdmin" source="IdeaBlade.EntityModel.Edm.v4.ObjectQueryProcessor:WriteGeneratedSql">SELECT [Extent1].[Id] AS [Id], [Extent1].[AutoId] AS [AutoId], [Extent1].[Name] AS [Name], [Extent1].[Creator] AS [Creator], [Extent1].[CreateDate] AS [CreateDate], [Extent1].[LastUpdater] AS [LastUpdater], [Extent1].[LastUpdate] AS [LastUpdate], [Extent1].[RowVersion] AS [RowVersion], [Extent1].[Login] AS [Login], [Extent1].[Secret] AS [Secret], [Extent1].[Salt] AS [Salt] FROM [dbo].[BOTSUser] AS [Extent1] WHERE ((CASE WHEN ([Extent1].[Id] IS NOT NULL) THEN cast(1 as bit) END) = 1) AND (N'BOTSAdmin' = [Extent1].[Login])</entry> <entry id="17" timestamp="2008-12-01T18:05:47" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerFetched</entry> <entry id="18" timestamp="2008-12-01T18:05:51" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerSaving</entry> <entry id="19" timestamp="2008-12-01T18:05:51" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EdmSaveHelper:<TraceChanges>b__51">BOTSUsers to be Modified: 1</entry> <entry id="20" timestamp="2008-12-01T18:05:57" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerSaved</entry> </log>
---- FAILED EXAMPLE
-------- app.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="ideaBlade.v4" type="IdeaBlade.Util.Configuration.v4.IdeaBladeSection, IdeaBlade.Util.v4, Version=4.2.1.6, Culture=neutral, PublicKeyToken=287b5094865421c0" /> </configSections> <ideaBlade.v4 version="4.00" useDTC="false" copyLocal="false" loginManagerRequired="false" clientApplicationType="Standard" testMode="false"> <probeAssemblyNames> <probeAssemblyName name="ServerModel" /> </probeAssemblyNames> <logging logFile="DebugLog.xml" archiveLogs="false" serviceName="" port="0" usesSeparateAppDomain="false" /> <objectServer isDistributed="false" remoteBaseURL=" http://localhost - http://localhost " serviceName="EntityService" serverPort="9009" proxyName="" proxyPort="0" sessionEncryptionKey="" /> <edmKeys> <edmKey connection="metadata=res://ServerModel/ServerModel.csdl|res://ServerModel/ServerModel.ssdl|res://ServerModel/ServerModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=BOTS;User ID=--------;Password=--------;Packet Size=8192;MultipleActiveResultSets=True"" containerName="ServerModel.ServerModelContext" logTraceString="true" name="Default" tag=""> <probeAssemblyNames> <probeAssemblyName name="DomainModel" /> <probeAssemblyName name="ServerModel" /> </probeAssemblyNames> </edmKey> </edmKeys> <notificationService enabled="false" serverPort="9010" clientPort="0" /> </ideaBlade.v4> </configuration>
-------- debuglog.xml
<?xml version="1.0"?><?xml:stylesheet href="DebugLog.xsl" type="text/xsl"?><log> <entry id="0" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFileXmlLogger:GetLogHeader">------------ Log Created ------------</entry> <entry id="1" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: app.config embedded in Assembly: AppHelper Tester, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - not found</entry> <entry id="2" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: app.config embedded in Assembly: AppHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f8d11d1c794cd11 - found</entry> <entry id="3" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">IdeaBladeConfig resolution: Logging file: C:\Documents and Settings\Dan\My Documents\~Dev\BOTS\bin\DebugLog.xml</entry> <entry id="4" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">Bound to .NET runtime version 2.0.50727.3053</entry> <entry id="5" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.TraceFns:Initialize">DevForce version 4.2.1.6</entry> <entry id="6" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.Util.v4.AuthHelper:LoadRuntimeLicense">IdeaBlade License: 'ProfessionalEF', KeyDate: 10/16/2008, AllowedSessions: 10000. Found on Assembly: 'DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f8d11d1c794cd11'</entry> <entry id="7" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.v4.FactoryFns:GetDataSourceKeyResolver">Probed for 'IDataSourceKeyResolver' and found SeverModel.DynamicDataSourceKeyResolver</entry> <entry id="8" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.v4.EntityServerProxy:CreateInstance">Loaded IdeaBlade.EntityModel.v4.EntityServerProxy</entry> <entry id="9" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.v4.EntityServiceApplication:OnServiceStartup">EntityService created</entry> <entry id="10" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.v4.EntityService:get_LocalInstance">Created local EntityService</entry> <entry id="11" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.Server.v4.EntityServer:.ctor">EntityServer created for DataSourceExtension: Local</entry> <entry id="12" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.v4.FactoryFns:GetDataSourceKeyResolver">Probed for 'IDataSourceKeyResolver' and found SeverModel.DynamicDataSourceKeyResolver</entry> <entry id="13" timestamp="2008-12-01T18:10:40" username="" source="IdeaBlade.EntityModel.Server.v4.SessionManager:GetLoginManager">Probed for 'IEntityLoginManager' and found SeverModel.LoginManager</entry> <entry id="14" timestamp="2008-12-01T18:10:40" username="BOTSAdmin" source="IdeaBlade.EntityModel.v4.IdGeneratorFactory:GetIdGenerator">Probed for 'IIdentityIdGenerator' and found IdeaBlade.EntityModel.v4.StoreGeneratedIdGenerator</entry> <entry id="15" timestamp="2008-12-01T18:10:40" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerFetching</entry> <entry id="16" timestamp="2008-12-01T18:10:40" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:Fetch">Fetch ... value(IdeaBlade.EntityModel.v4.EntityGroupProxy`1[DomainModel.BOTSUser]).OfType().Where(newObj => (newObj.Login = "BOTSAdmin")).Select(newObj => newObj).FirstOrDefault()</entry> <entry id="17" timestamp="2008-12-01T18:10:40" username="BOTSAdmin" source="IdeaBlade.EntityModel.v4.IdGeneratorFactory:GetIdGenerator">Probed for 'IIdentityIdGenerator' and found IdeaBlade.EntityModel.v4.StoreGeneratedIdGenerator</entry> <entry id="18" timestamp="2008-12-01T18:10:48" username="BOTSAdmin" source="IdeaBlade.EntityModel.Edm.v4.ObjectQueryProcessor:WriteGeneratedSql">SELECT [Extent1].[Id] AS [Id], [Extent1].[AutoId] AS [AutoId], [Extent1].[Name] AS [Name], [Extent1].[Creator] AS [Creator], [Extent1].[CreateDate] AS [CreateDate], [Extent1].[LastUpdater] AS [LastUpdater], [Extent1].[LastUpdate] AS [LastUpdate], [Extent1].[RowVersion] AS [RowVersion], [Extent1].[Login] AS [Login], [Extent1].[Secret] AS [Secret], [Extent1].[Salt] AS [Salt] FROM [dbo].[BOTSUser] AS [Extent1] WHERE ((CASE WHEN ([Extent1].[Id] IS NOT NULL) THEN cast(1 as bit) END) = 1) AND (N'BOTSAdmin' = [Extent1].[Login])</entry> <entry id="19" timestamp="2008-12-01T18:10:48" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerFetched</entry> <entry id="20" timestamp="2008-12-01T18:10:49" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerSaving</entry> <entry id="21" timestamp="2008-12-01T18:10:49" username="BOTSAdmin" source="IdeaBlade.EntityModel.v4.IdGeneratorFactory:GetIdGenerator">Probed for 'IIdentityIdGenerator' and found IdeaBlade.EntityModel.v4.StoreGeneratedIdGenerator</entry> <entry id="22" timestamp="2008-12-01T18:10:49" username="BOTSAdmin" source="IdeaBlade.EntityModel.Server.v4.EntityServer:GetInstanceImplementing">Unable to locate an implementation of: IdeaBlade.EntityModel.v4.IEntityServerSaved</entry> </log>
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Posted By: kimj
Date Posted: 02-Dec-2008 at 10:09am
|
This is a likely a bug, which has (hopefully) been fixed in current bits and will be available in the 4.2.2.x release later this month. The problem was that the DevForce save logic was using the name of the EdmKey to drive processing, and with a DataSourceKeyResolver in place the name was not matching the DataSourceKeyNameAttribute on the entities.
|
Posted By: dkearney1
Date Posted: 02-Dec-2008 at 10:20am
Thanks, I'll be looking forward to that fix.
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
Posted By: kimj
Date Posted: 02-Dec-2008 at 6:36pm
|
A few more things -
- This should work in your current DevForce version, if you ensure that the name of the EdmKey you return from the custom DataSourceKeyResolver starts with the "original" key name, i.e., the name used in the DataSourceKeyName attribute on the entities. You can append to this name using an underscore as a separator if you'd like to make it unique, e.g., "Default_FromResolver".
- You probably already know this, but for the record ... You can locate the custom DataSourceKeyResolver in any assembly, but that assembly name must be specified in the <probeAssemblyNames> collection at the root level of the IdeaBlade configuration.
|
Posted By: dkearney1
Date Posted: 02-Dec-2008 at 8:18pm
Using the original name of my key, which you correctly guessed to be "Default" :) , as the prefix for the new key worked as describe, thanks.
And thanks for the tip about locating my implementations in any assembly. It just happens to be convenient to put them in the ServerModel.dll.
------------- Dan
“In anything at all, perfection is finally attained not when there is no
longer anything to add, but when there is no longer anything to take away.”
Saint-Exupéry
Wind, Sand, and Stars
|
|