/// <summary> /// Global method to retrieve the factory key from an object, as defined in its /// SessionFactoryAttribute, if available. Defaults to the DefaultFactoryKey /// if not found. /// </summary> public static string GetKeyFrom(object anObject) { if (!NHibernateSession.IsConfiguredForMultipleDatabases()) { return(NHibernateSession.DefaultFactoryKey); } Type objectType = anObject.GetType(); object[] attributes = objectType.GetCustomAttributes(typeof(SessionFactoryAttribute), true); if (attributes.Length > 0) { SessionFactoryAttribute attribute = (SessionFactoryAttribute)attributes[0]; return(attribute.FactoryKey); } return(NHibernateSession.DefaultFactoryKey); }
private ISession GetSessionFor(object entity) { string factoryKey = SessionFactoryAttribute.GetKeyFrom(entity); return(NHibernateSession.CurrentFor(factoryKey)); }