public List <T> AddNew <T>(IEnumerable <T> dataset, DataProviderContext dataProviderContext) where T : class, IData { SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(typeof(T)); if (sqlDataTypeStore == null) { throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", typeof(T).FullName)); } var resultDataset = new List <T>(); using (var dataContext = CreateDataContext()) { foreach (IData data in dataset) { Verify.ArgumentCondition(data != null, "dataset", "Data set may not contain nulls"); IData newData = sqlDataTypeStore.AddNew(data, dataProviderContext, dataContext); (newData as IEntity).Commit(); CheckConstraints(newData); resultDataset.Add((T)newData); } SubmitChanges(dataContext); } return(resultDataset); }
private InitializeStoreResult EmbedDataContextInfo(InterfaceGeneratedClassesInfo initInfo, Type dataContextType) { var result = new InitializeStoreResult(); if (initInfo.InterfaceType == null) { return(result); } result.InterfaceType = initInfo.InterfaceType; var sqlDataTypeStoreTables = new Dictionary <SqlDataTypeStoreTableKey, SqlDataTypeStoreTable>(); foreach (SqlDataTypeStoreDataScope storeDataScope in initInfo.DataScopes) { var key = new SqlDataTypeStoreTableKey(storeDataScope.DataScopeName, storeDataScope.CultureName); result.TableNames.Add(key, storeDataScope.TableName); Verify.IsNotNull(initInfo.Fields, "Fields collection is null"); StoreTypeInfo fieldInfo; if (!initInfo.Fields.TryGetValue(key, out fieldInfo)) { continue; } Verify.IsNotNull(fieldInfo, "Field info is missing"); FieldInfo dataContextFieldInfo = dataContextType != null ? dataContextType.GetField(fieldInfo.FieldName) : fieldInfo.DataContextField; Type sqlDataProvdierHelperType = fieldInfo.SqlHelperClass; var sqlDataProviderHelper = (ISqlDataProviderHelper)Activator.CreateInstance(sqlDataProvdierHelperType); var sqlDataTypeStoreTable = new SqlDataTypeStoreTable( initInfo.DataTypeDescriptor.DataTypeId, dataContextFieldInfo, sqlDataProviderHelper, fieldInfo.FieldName, fieldInfo.FieldType); _createdSqlDataTypeStoreTables.Add(sqlDataTypeStoreTable); sqlDataTypeStoreTables.Add(key, sqlDataTypeStoreTable); } var sqlDataTypeStore = new SqlDataTypeStore(result.InterfaceType, sqlDataTypeStoreTables, initInfo.DataTypeDescriptor.IsCodeGenerated, _sqlDataTypeStoresContainer); result.SqlDataTypeStore = sqlDataTypeStore; return(result); }
/// <summary> /// This method adds the support of the given data interface type to the xml data provider. /// </summary> /// <param name="interfaceType"></param> /// <param name="sqlDataTypeStore"></param> internal void AddSupportedDataTypeStore(Type interfaceType, SqlDataTypeStore sqlDataTypeStore) { _sqlDataTypeStores.Add(interfaceType, sqlDataTypeStore); _supportedInterfaces.Add(interfaceType); AddKnownInterface(interfaceType); if (sqlDataTypeStore.IsGeneretedDataType) { _generatedInterfaces.Add(interfaceType); } }
/// <summary> /// This method adds the support of the given data interface type to the xml data provider. /// </summary> /// <param name="interfaceType"></param> /// <param name="sqlDataTypeStore"></param> internal void AddSupportedDataTypeStore(Type interfaceType, SqlDataTypeStore sqlDataTypeStore) { Verify.That(!_sqlDataTypeStores.ContainsKey(interfaceType), "Type {0} is registered in the SqlDataProvider configuration multiple types", interfaceType); _sqlDataTypeStores.Add(interfaceType, sqlDataTypeStore); _supportedInterfaces.Add(interfaceType); AddKnownInterface(interfaceType); if (sqlDataTypeStore.IsGeneretedDataType) { _generatedInterfaces.Add(interfaceType); } }
public IQueryable <T> GetData <T>() where T : class, IData { using (TimerProfilerFacade.CreateTimerProfiler(typeof(T).ToString())) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } SqlDataTypeStore result = _sqlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); return((IQueryable <T>)result.GetQueryable()); } }
public void Delete(IEnumerable <DataSourceId> dataSourceIds, DataProviderContext dataProivderContext) { DataContext dataContext = null; try { foreach (DataSourceId dataSourceId in dataSourceIds) { if (dataSourceId == null) { throw new ArgumentException("dataSourceIds contains nulls"); } using (new DataScope(dataSourceId.DataScopeIdentifier, dataSourceId.LocaleScope)) { SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(dataSourceId.InterfaceType); if (sqlDataTypeStore == null) { throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", dataSourceId.InterfaceType.FullName)); } IData data = sqlDataTypeStore.GetDataByDataId(dataSourceId.DataId, dataProivderContext); Verify.That(data != null, "Row has already been deleted"); if (dataContext == null) { dataContext = CreateDataContext(); } sqlDataTypeStore.RemoveData(data, dataContext); } } if (dataContext != null) { SubmitChanges(dataContext); } } finally { if (dataContext != null) { dataContext.Dispose(); } } }
public T GetData <T>(IDataId dataId) where T : class, IData { Verify.ArgumentNotNull(dataId, "dataId"); using (TimerProfilerFacade.CreateTimerProfiler(string.Format("dataId ({0})", typeof(T)))) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } SqlDataTypeStore result = _sqlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); IData data = result.GetDataByDataId(dataId, _dataProviderContext); return((T)data); } }
private InitializeStoreResult EmbedDataContextInfo(InterfaceGeneratedClassesInfo initInfo, Type dataContextType) { var result = new InitializeStoreResult(); if (initInfo.InterfaceType == null) { return result; } result.InterfaceType = initInfo.InterfaceType; var sqlDataTypeStoreTables = new Dictionary<SqlDataTypeStoreTableKey, SqlDataTypeStoreTable>(); foreach (SqlDataTypeStoreDataScope storeDataScope in initInfo.DataScopes) { var key = new SqlDataTypeStoreTableKey(storeDataScope.DataScopeName, storeDataScope.CultureName); result.TableNames.Add(key, storeDataScope.TableName); Verify.IsNotNull(initInfo.Fields, "Fields collection is null"); StoreTypeInfo fieldInfo; if (!initInfo.Fields.TryGetValue(key, out fieldInfo)) { continue; } Verify.IsNotNull(fieldInfo, "Field info is missing"); FieldInfo dataContextFieldInfo = dataContextType != null ? dataContextType.GetField(fieldInfo.FieldName) : fieldInfo.DataContextField; Type sqlDataProvdierHelperType = fieldInfo.SqlHelperClass; var sqlDataProviderHelper = (ISqlDataProviderHelper)Activator.CreateInstance(sqlDataProvdierHelperType); var sqlDataTypeStoreTable = new SqlDataTypeStoreTable( initInfo.DataTypeDescriptor.DataTypeId, dataContextFieldInfo, sqlDataProviderHelper, fieldInfo.FieldName, fieldInfo.FieldType); _createdSqlDataTypeStoreTables.Add(sqlDataTypeStoreTable); sqlDataTypeStoreTables.Add(key, sqlDataTypeStoreTable); } var sqlDataTypeStore = new SqlDataTypeStore(result.InterfaceType, sqlDataTypeStoreTables, initInfo.DataTypeDescriptor.IsCodeGenerated, _sqlDataTypeStoresContainer); result.SqlDataTypeStore = sqlDataTypeStore; return result; }