Esempio n. 1
0
        private MtTypeDefinition ResolveMtType(ISqlConnectionProvider connectionProvider, Type clrType, IMtTypeStorageProvider typeStorageProvider, bool forceComplexType, bool storeIfNew)
        {
            MtTypeDefinition typeDefinition;

            lock (_clrTypeMappings)
            {
                if (!_clrTypeMappings.TryGetValue(clrType, out typeDefinition))
                {
                    if (typeStorageProvider.TryLoadType(connectionProvider, clrType, out typeDefinition))
                    {
                        CacheTypeDependences(connectionProvider, typeDefinition, typeStorageProvider);
                        return(typeDefinition);
                    }

                    if (!storeIfNew)
                    {
                        return(null);
                    }

                    typeDefinition = BuildMtType(connectionProvider, clrType, typeStorageProvider, forceComplexType);
                    typeStorageProvider.PersistType(connectionProvider, typeDefinition);
                    _clrTypeMappings[clrType] = typeDefinition;
                    _isUnsavedType.Add(typeDefinition.Id);
                }
            }

            return(typeDefinition);
        }
Esempio n. 2
0
        private void CacheTypeDependences(ISqlConnectionProvider connectionProvider, MtTypeDefinition typeDefinition, IMtTypeStorageProvider typeStorageProvider)
        {
            if (_clrTypeMappings.ContainsKey(typeDefinition.ClrType))
            {
                return;
            }

            // this type was not saved to the DB yet. Request storage provider to persist this type in storage provider's unit of work scope.
            // this logic shall not create duplicates because storage provider checks if type was alredy persisted before saving.

            if (_isUnsavedType.Contains(typeDefinition.Id))
            {
                typeStorageProvider.PersistType(connectionProvider, typeDefinition);
            }

            _clrTypeMappings[typeDefinition.ClrType] = typeDefinition;

            if (typeDefinition.Properties != null)
            {
                foreach (var mtPropertyInfo in typeDefinition.Properties)
                {
                    CacheTypeDependences(connectionProvider, mtPropertyInfo.MtPropertyType, typeStorageProvider);
                }
            }
        }