internal DbGeographyAdapter(DbGeography value) { DebugCheck.NotNull(value); _value = value; }
/// <summary> /// Simple constructor - just needs the name and type of the column /// </summary> /// <param name="type"> column type </param> /// <param name="name"> column name </param> internal ColumnMap(TypeUsage type, string name) { DebugCheck.NotNull(type); _type = type; _name = name; }
public static EntityType GetKeyNamesType(this EntityType table) { DebugCheck.NotNull(table); return((EntityType)table.Annotations.GetAnnotation(KeyNamesTypeAnnotation)); }
internal void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder) { Check.NotNull(columnMappingBuilder, "columnMappingBuilder"); if (!columnMappingBuilder.PropertyPath.Any() || _columnMappings.Contains(columnMappingBuilder)) { throw new ArgumentException(Strings.InvalidColumnBuilderArgument("columnBuilderMapping")); } DebugCheck.NotNull(columnMappingBuilder.ColumnProperty); _columnMappings.Add(columnMappingBuilder); StructuralTypeMapping structuralTypeMapping = this; EdmProperty property; // Turn the property path into a mapping fragment nested tree structure. var i = 0; for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++) { // The first n-1 properties are complex so we just need to build // a corresponding tree of complex type mappings. property = columnMappingBuilder.PropertyPath[i]; var complexPropertyMapping = structuralTypeMapping .PropertyMappings .OfType <ComplexPropertyMapping>() .SingleOrDefault(pm => ReferenceEquals(pm.Property, property)); ComplexTypeMapping complexTypeMapping = null; if (complexPropertyMapping == null) { complexTypeMapping = new ComplexTypeMapping(false); complexTypeMapping.AddType(property.ComplexType); complexPropertyMapping = new ComplexPropertyMapping(property); complexPropertyMapping.AddTypeMapping(complexTypeMapping); structuralTypeMapping.AddPropertyMapping(complexPropertyMapping); } structuralTypeMapping = complexTypeMapping ?? complexPropertyMapping.TypeMappings.Single(); } // The last property has to be a scalar mapping to the target column. // Extract it and create the scalar mapping leaf node, ensuring that we // set the target column. property = columnMappingBuilder.PropertyPath[i]; var scalarPropertyMapping = structuralTypeMapping .PropertyMappings .OfType <ScalarPropertyMapping>() .SingleOrDefault(pm => ReferenceEquals(pm.Property, property)); if (scalarPropertyMapping == null) { scalarPropertyMapping = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty); structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping); columnMappingBuilder.SetTarget(scalarPropertyMapping); } else { scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty; } }
private ToDecisionDiagramConverter(ConversionContext <T_Identifier> context) { DebugCheck.NotNull(context); _context = context; }
public ParameterInliner(DbParameterCollection parameters) { DebugCheck.NotNull(parameters); _parameters = parameters; }
private static ICustomTypeDescriptor GetTypeDescriptor(Type type) { DebugCheck.NotNull(type); return(new AssociatedMetadataTypeTypeDescriptionProvider(type).GetTypeDescriptor(type)); }
// <summary> // Set the proxy object's private entity wrapper field value to the specified entity wrapper object. // The proxy object (representing the wrapped entity) is retrieved from the wrapper itself. // </summary> // <param name="wrapper"> Wrapper object to be referenced by the proxy. </param> // <returns> The supplied entity wrapper. This is done so that this method can be more easily composed within lambda expressions (such as in the materializer). </returns> internal IEntityWrapper SetEntityWrapper(IEntityWrapper wrapper) { DebugCheck.NotNull(wrapper); DebugCheck.NotNull(wrapper.Entity); return(Proxy_SetEntityWrapper(wrapper.Entity, wrapper) as IEntityWrapper); }
internal EntityProxyTypeInfo( Type proxyType, ClrEntityType ospaceEntityType, DynamicMethod initializeCollections, List <PropertyInfo> baseGetters, List <PropertyInfo> baseSetters, MetadataWorkspace workspace) { DebugCheck.NotNull(proxyType); DebugCheck.NotNull(workspace); _proxyType = proxyType; _entityType = ospaceEntityType; _initializeCollections = initializeCollections; foreach (var relationshipType in GetAllRelationshipsForType(workspace, proxyType)) { _navigationPropertyAssociationTypes.Add(relationshipType.FullName, relationshipType); if (relationshipType.Name != relationshipType.FullName) { // Sometimes there isn't enough metadata to have a container name // Default codegen doesn't qualify names _navigationPropertyAssociationTypes.Add(relationshipType.Name, relationshipType); } } var entityWrapperField = proxyType.GetField( EntityWrapperFieldName, BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); var Object_Parameter = Expression.Parameter(typeof(object), "proxy"); var Value_Parameter = Expression.Parameter(typeof(object), "value"); Debug.Assert(entityWrapperField != null, "entityWrapperField does not exist"); // Create the Wrapper Getter var lambda = Expression.Lambda <Func <object, object> >( Expression.Field( Expression.Convert(Object_Parameter, entityWrapperField.DeclaringType), entityWrapperField), Object_Parameter); var getEntityWrapperDelegate = lambda.Compile(); Proxy_GetEntityWrapper = (object proxy) => { // This code validates that the wrapper points to the proxy that holds the wrapper. // This guards against mischief by switching this wrapper out for another one obtained // from a different object. var wrapper = ((IEntityWrapper)getEntityWrapperDelegate(proxy)); if (wrapper != null && !ReferenceEquals(wrapper.Entity, proxy)) { throw new InvalidOperationException(Strings.EntityProxyTypeInfo_ProxyHasWrongWrapper); } return(wrapper); }; // Create the Wrapper setter Proxy_SetEntityWrapper = Expression.Lambda <Func <object, object, object> >( Expression.Assign( Expression.Field( Expression.Convert(Object_Parameter, entityWrapperField.DeclaringType), entityWrapperField), Value_Parameter), Object_Parameter, Value_Parameter).Compile(); var PropertyName_Parameter = Expression.Parameter(typeof(string), "propertyName"); var baseGetterMethod = proxyType.GetPublicInstanceMethod("GetBasePropertyValue", typeof(string)); if (baseGetterMethod != null) { _baseGetter = Expression.Lambda <Func <object, string, object> >( Expression.Call(Expression.Convert(Object_Parameter, proxyType), baseGetterMethod, PropertyName_Parameter), Object_Parameter, PropertyName_Parameter).Compile(); } var PropertyValue_Parameter = Expression.Parameter(typeof(object), "propertyName"); var baseSetterMethod = proxyType.GetPublicInstanceMethod("SetBasePropertyValue", typeof(string), typeof(object)); if (baseSetterMethod != null) { _baseSetter = Expression.Lambda <Action <object, string, object> >( Expression.Call( Expression.Convert(Object_Parameter, proxyType), baseSetterMethod, PropertyName_Parameter, PropertyValue_Parameter), Object_Parameter, PropertyName_Parameter, PropertyValue_Parameter).Compile(); } _propertiesWithBaseGetter = new HashSet <string>(baseGetters.Select(p => p.Name)); _propertiesWithBaseSetter = new HashSet <string>(baseSetters.Select(p => p.Name)); _createObject = DelegateFactory.CreateConstructor(proxyType); }
// <summary> // Constructor - loads all resources into the _children collection // </summary> // <param name="children"> A list of collections to aggregate </param> public MetadataArtifactLoaderComposite(List <MetadataArtifactLoader> children) { DebugCheck.NotNull(children); _children = new ReadOnlyCollection <MetadataArtifactLoader>(new List <MetadataArtifactLoader>(children)); }
internal MetadataOptimization(MetadataWorkspace workspace) { DebugCheck.NotNull(workspace); _workspace = workspace; }
//End identical code #region Add internal override void AddToLocalCache(IEntityWrapper wrappedEntity, bool applyConstraints) { DebugCheck.NotNull(wrappedEntity); WrappedRelatedEntities[(TEntity)wrappedEntity.Entity] = wrappedEntity; }
internal override bool CanSetEntityType(IEntityWrapper wrappedEntity) { DebugCheck.NotNull(wrappedEntity); return(wrappedEntity.Entity is TEntity); }
/// <summary> /// Initializes a new instance of the <see cref="DbEntityEntry{TEntity}" /> class. /// </summary> /// <param name="internalEntityEntry"> The internal entry. </param> internal DbEntityEntry(InternalEntityEntry internalEntityEntry) { DebugCheck.NotNull(internalEntityEntry); _internalEntityEntry = internalEntityEntry; }
private bool QueryExists(string contextKey) { DebugCheck.NotNull(contextKey); if (_initialExistence == DatabaseExistenceState.DoesNotExist) { return(false); } DbConnection connection = null; try { connection = CreateConnection(); if (_initialExistence == DatabaseExistenceState.Unknown) { using (var context = CreateContext(connection)) { if (!context.Database.Exists()) { return(false); } } } foreach (var schema in _schemas.Reverse()) { using (var context = CreateContext(connection, schema)) { _currentSchema = schema; _contextKeyColumnExists = true; // Do the context-key specific query first, since if it succeeds we can avoid // doing the more general query. try { using (new TransactionScope(TransactionScopeOption.Suppress)) { contextKey = contextKey.RestrictTo(_contextKeyMaxLength); if (context.History.Count(hr => hr.ContextKey == contextKey) > 0) { return(true); } } } catch (EntityException entityException) { if (_permissionDeniedDetector != null && _permissionDeniedDetector(entityException.InnerException)) { throw; } _contextKeyColumnExists = false; } // If the context-key specific query failed, then try the general query to see // if there is a history table in this schema at all if (!_contextKeyColumnExists) { try { using (new TransactionScope(TransactionScopeOption.Suppress)) { context.History.Count(); } } catch (EntityException entityException) { if (_permissionDeniedDetector != null && _permissionDeniedDetector(entityException.InnerException)) { throw; } _currentSchema = null; } } } } } finally { DisposeConnection(connection); } return(!string.IsNullOrWhiteSpace(_currentSchema)); }
public static object GetConfiguration(this EdmProperty property) { DebugCheck.NotNull(property); return(property.Annotations.GetConfiguration()); }
public HistoryRepository( InternalContext usersContext, string connectionString, DbProviderFactory providerFactory, string contextKey, int?commandTimeout, Func <DbConnection, string, HistoryContext> historyContextFactory, IEnumerable <string> schemas = null, DbContext contextForInterception = null, DatabaseExistenceState initialExistence = DatabaseExistenceState.Unknown, Func <Exception, bool> permissionDeniedDetector = null) : base(usersContext, connectionString, providerFactory) { DebugCheck.NotEmpty(contextKey); DebugCheck.NotNull(historyContextFactory); _initialExistence = initialExistence; _permissionDeniedDetector = permissionDeniedDetector; _commandTimeout = commandTimeout; _existingTransaction = usersContext.TryGetCurrentStoreTransaction(); _schemas = new[] { EdmModelExtensions.DefaultSchema } .Concat(schemas ?? Enumerable.Empty <string>()) .Distinct(); _contextForInterception = contextForInterception; _historyContextFactory = historyContextFactory; DbConnection connection = null; try { connection = CreateConnection(); using (var context = CreateContext(connection)) { var historyRowEntity = ((IObjectContextAdapter)context).ObjectContext .MetadataWorkspace .GetItems <EntityType>(DataSpace.CSpace) .Single(et => et.GetClrType() == typeof(HistoryRow)); var maxLength = historyRowEntity .Properties .Single(p => p.GetClrPropertyInfo().IsSameAs(MigrationIdProperty)) .MaxLength; _migrationIdMaxLength = maxLength.HasValue ? maxLength.Value : HistoryContext.MigrationIdMaxLength; maxLength = historyRowEntity .Properties .Single(p => p.GetClrPropertyInfo().IsSameAs(ContextKeyProperty)) .MaxLength; _contextKeyMaxLength = maxLength.HasValue ? maxLength.Value : HistoryContext.ContextKeyMaxLength; } } finally { DisposeConnection(connection); } _contextKey = contextKey.RestrictTo(_contextKeyMaxLength); }
public static void SetConfiguration(this EdmProperty property, object configuration) { DebugCheck.NotNull(property); property.GetMetadataProperties().SetConfiguration(configuration); }
/// <summary> /// Provides a standard helper method for quoting identifiers /// </summary> /// <param name="identifier"> Identifier to be quoted. Does not validate that this identifier is valid. </param> /// <returns> Quoted string </returns> internal static string QuoteIdentifier(string identifier) { DebugCheck.NotNull(identifier); return("[" + identifier.Replace("]", "]]") + "]"); }
public static int?GetOrder(this EdmProperty tableColumn) { DebugCheck.NotNull(tableColumn); return((int?)tableColumn.Annotations.GetAnnotation(OrderAnnotation)); }
internal void AddConditionProperty(ConditionPropertyMapping conditionPropertyMap) { DebugCheck.NotNull(conditionPropertyMap); AddConditionProperty(conditionPropertyMap, _ => { }); }
public static void SetOrder(this EdmProperty tableColumn, int order) { DebugCheck.NotNull(tableColumn); tableColumn.GetMetadataProperties().SetAnnotation(OrderAnnotation, order); }
public MigrationsConfigurationFinder(TypeFinder typeFinder) { DebugCheck.NotNull(typeFinder); _typeFinder = typeFinder; }
public static string GetUnpreferredUniqueName(this EdmProperty tableColumn) { DebugCheck.NotNull(tableColumn); return((string)tableColumn.Annotations.GetAnnotation(UnpreferredUniqueNameAnnotation)); }
internal static Funcletizer CreateQueryFuncletizer(ObjectContext rootContext) { DebugCheck.NotNull(rootContext); return(new Funcletizer(Mode.ConventionalQuery, rootContext, null, null)); }
public static void SetUnpreferredUniqueName(this EdmProperty tableColumn, string name) { DebugCheck.NotNull(tableColumn); tableColumn.GetMetadataProperties().SetAnnotation(UnpreferredUniqueNameAnnotation, name); }
public static DatabaseName GetTableName(this EntityType table) { DebugCheck.NotNull(table); return((DatabaseName)table.Annotations.GetAnnotation(TableNameAnnotation)); }
/// <summary>Gets the spatial services for the <see cref="T:System.Data.Entity.Core.Common.DbProviderServices" />.</summary> /// <returns>The spatial services.</returns> /// <param name="key">Information about the database that the spatial services will be used for.</param> public DbSpatialServices GetSpatialServices(DbProviderInfo key) { DebugCheck.NotNull(key); return(GetSpatialServices(_resolver.Value, key, () => this)); }
// <summary> // Structured columnmap constructor // </summary> // <param name="type"> datatype for this column </param> // <param name="name"> column name </param> // <param name="properties"> list of properties </param> internal StructuredColumnMap(TypeUsage type, string name, ColumnMap[] properties) : base(type, name) { DebugCheck.NotNull(properties); m_properties = properties; }
// effects: Creates an empty map with keys compared using comparer internal KeyToListMap(IEqualityComparer <TKey> comparer) { DebugCheck.NotNull(comparer); m_map = new Dictionary <TKey, List <TValue> >(comparer); }