I am writing a program that stores data in one database and references
a medical records system via an API I am writing using AR. Currently,
the API and the scheduling system are compiled into one program. I
have abstracted the ActiveRecord class and created an
AhtActiveRecordBase class in which I override the update/save/delete
functions to ensure we cannot write back to our EMR.
This part works fine. When I only connect to one DB it works fine, the
issue comes when I use multiple configuration sections to connect to
more than one db. Whenever I access the EMR db after adding the
database,

I get a System.Collections.Generic.KeyNotFoundException  exception. I
am attaching the code and the stack trace in hopes that someone can
point me in the right direction. I am using the daily build for this.

Thank you for your help!
Chris Sims
Senior Software Specialist
NHS Management, LLC.

Config File:
  <activerecord>
    <config>
      <add key="connection.driver_class"
value="NHibernate.Driver.SqlClientDriver" />
      <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" /
>
      <add key="connection.provider"
value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="connection.connection_string_name" value="main" />
      <add value="NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle" key="proxyfactory.factory_class" />
      <add key="connection.isolation" value="ReadUncommitted" />
     </config>

    <config type="Scheduler.Core.AhtActiveRecordBase`1,
Scheduler.Core">
      <add key="connection.driver_class"
value="NHibernate.Driver.SqlClientDriver" />
      <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" /
>
      <add key="connection.provider"
value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="connection.connection_string_name" value="AHT" />
      <add value="NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle" key="proxyfactory.factory_class" />
    </config>
  </activerecord>

Init Statement:
 ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance
                                        //various types omitted from code 
listing for brevity
                    , typeof(ServiceProviderType)
                    , typeof(ResidentServiceProviders)
                    , typeof(AhtActiveRecordBase<>)
                    );

Error Statement:
        List<Facility> facs = new List<Facility>(Facility.FindAll());

AhtActiveRecordBase<>:
    public abstract class AhtActiveRecordBase<T> : ActiveRecordBase<T>
    {
        #region Force read only, remove Save/Update/Create/Delete
functionality
        public override void Save()
        {}
        public override void SaveAndFlush()
        {}
        public override void Delete()
        {}
        public override void DeleteAndFlush()
        {}
        public override void Update()
        {}
        public override void UpdateAndFlush()
        {}
        public override void Create()
        {}
        public override void CreateAndFlush()
        {}
        #endregion
    }

Facility
    [ActiveRecord("FacilityList", Schema="NHS",
Access=PropertyAccess.NosetterCamelcase)]
    public partial class Facility : AhtActiveRecordBase<Facility>
        { // large amount of fields/properties ommitted for brevity }

The Exception
System.Collections.Generic.KeyNotFoundException was unhandled
  Message="The given key was not present in the dictionary."
  Source="mscorlib"
  StackTrace:
       at System.ThrowHelper.ThrowKeyNotFoundException()
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at NHibernate.Cfg.Configuration.Mapping.GetPersistentClass
(String className)
       at NHibernate.Cfg.Configuration.Mapping.GetIdentifierType
(String className)
       at NHibernate.Type.EntityType.GetIdentifierType(IMapping
factory)
       at NHibernate.Type.EntityType.GetIdentifierOrUniqueKeyType
(IMapping factory)
       at NHibernate.Type.ManyToOneType.GetColumnSpan(IMapping
mapping)
       at NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping)
       at NHibernate.Mapping.ToOne.IsValid(IMapping mapping)
       at NHibernate.Mapping.Property.IsValid(IMapping mapping)
       at NHibernate.Mapping.PersistentClass.Validate(IMapping
mapping)
       at NHibernate.Mapping.RootClass.Validate(IMapping mapping)
       at NHibernate.Cfg.Configuration.Validate()
       at NHibernate.Cfg.Configuration.BuildSessionFactory()
       at
Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory
(Type type) in c:\castle\ActiveRecord\Castle.ActiveRecord\Framework
\SessionFactoryHolder.cs:line 135
       at
Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateScopeSession
(Type type) in c:\castle\ActiveRecord\Castle.ActiveRecord\Framework
\SessionFactoryHolder.cs:line 296
       at
Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession(Type
type) in c:\castle\ActiveRecord\Castle.ActiveRecord\Framework
\SessionFactoryHolder.cs:line 182
       at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type
targetType, Order[] orders, ICriterion[] criteria) in c:\castle
\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:line
997
       at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type
targetType) in c:\castle\ActiveRecord\Castle.ActiveRecord\Framework
\ActiveRecordBase.cs:line 982
       at Castle.ActiveRecord.ActiveRecordBase`1.FindAll() in c:\castle
\ActiveRecord\Castle.ActiveRecord\Framework
\ActiveRecordBase.Generic.cs:line 341
       at Scheduler.BuildSchedule.Program.Main(String[] args) in C:
\SharpProjects\EnhancedScheduler\Scheduler.BuildSchedule
\Program.cs:line 107
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String
[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
       at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to