示例#1
0
        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);
        }
        /// <exclude />
        internal static ITable GetTable(DataContext _dataContext, SqlDataTypeStoreTable storeInformation)
        {
            FieldInfo fi = storeInformation.DataContextQueryableFieldInfo;

            Verify.IsNotNull(fi, "Missing FieldInfo for a DataContext field.");

            object value = fi.GetValue(_dataContext);

            if (value == null)
            {
                var helperClassFieldInfo = _dataContext.GetType().GetField("_sqlDataContextHelperClass", BindingFlags.NonPublic | BindingFlags.Instance);
                Verify.IsNotNull(helperClassFieldInfo, "Helper field isn't exist in DataContext object.");

                var helper = helperClassFieldInfo.GetValue(_dataContext) as SqlDataContextHelperClass;
                Verify.That(helper != null, "Helper object has not been set");

                helper.EnsureTableInitialized(fi.Name);

                value = helper._tables[fi.Name];
            }
            return(Verify.ResultNotNull(value as ITable));
        }
        public IData AddNew(IData dataToAdd, DataProviderContext dataProivderContext, DataContext dataContext)
        {
            SqlDataTypeStoreTable storeTable = GetCurrentTable();

            return(storeTable.SqlDataProviderHelper.AddData((ISqlDataContext)dataContext, dataToAdd, dataProivderContext));
        }
        public void RemoveData(IData dataToRemove, DataContext dataContext)
        {
            SqlDataTypeStoreTable storeTable = GetCurrentTable();

            storeTable.SqlDataProviderHelper.RemoveData((ISqlDataContext)dataContext, dataToRemove);
        }
        public IData GetDataByDataId(IDataId dataId, DataProviderContext dataProivderContext)
        {
            SqlDataTypeStoreTable storage = GetCurrentTable();

            return(storage.SqlDataProviderHelper.GetDataById(GetQueryable(), dataId, dataProivderContext));
        }