예제 #1
0
        protected override void OnSetModel(object model, Type type)
        {
            var dataModel = model as TableDataModel;

            if (dataModel == null)
            {
                return;
            }

            var logicModel = dataModel.Logic;
            var tableModel = dataModel.Table;

            var queryGen = new QueryGenerator(DataContext, logicModel);

            sqlDs.ConnectionString = GetConnectionString();

            sqlDs.InsertCommand = queryGen.InsertQuery();
            sqlDs.UpdateCommand = queryGen.UpdateQuery();
            sqlDs.DeleteCommand = queryGen.DeleteQuery();
            sqlDs.SelectCommand = queryGen.SelectQuery();

            foreach (var pair in queryGen.PrimaryColumnsParams)
            {
                sqlDs.UpdateParameters.Add(pair.Key, pair.Value);
            }

            foreach (var pair in queryGen.PrimaryColumnsParams)
            {
                sqlDs.DeleteParameters.Add(pair.Key, pair.Value);
            }

            sqlDs.CacheKeyDependency    = sqlDs.SelectCommand.ComputeMd5();
            sqlDs.CacheExpirationPolicy = DataSourceCacheExpiry.Sliding;
            sqlDs.CacheDuration         = 900;

            var primaryColumns = tableModel.Columns.Where(n => n.IsPrimary).ToList();

            if (primaryColumns.Count == 0)
            {
                primaryColumns = tableModel.Columns;
            }

            var keyFields = String.Join(";", primaryColumns.Select(n => n.Name));

            gvData.KeyFieldName = keyFields;
        }