Example #1
0
        public IDataModel LoadModel(string source, string command, object prms = null)
        {
            var modelReader = new DataModelReader();

            using (var p = _host.Profiler.Start(ProfileAction.Sql, command))
            {
                ReadData(source, command,
                         setParams: (prm) => modelReader.SetParameters(prm, prms),
                         onRead: (no, rdr) => modelReader.ProcessOneRecord(rdr),
                         onMetadata: (no, rdr) => modelReader.ProcessOneMetadata(rdr));
            }
            modelReader.PostProcess();
            return(modelReader.DataModel);
        }
Example #2
0
        public async Task <IDataModel> SaveModelAsync(String source, String command, Object data, Object prms = null)
        {
            var dataReader = new DataModelReader();
            var dataWriter = new DataModelWriter();

            using (var p = _host.Profiler.Start(ProfileAction.Sql, command))
            {
                var metadataCommand = command.Replace(".Update", ".Metadata");
                using (var cnn = await GetConnectionAsync(source))
                {
                    using (var cmd = cnn.CreateCommandSP(metadataCommand))
                    {
                        using (var rdr = await cmd.ExecuteReaderAsync())
                        {
                            do
                            {
                                dataWriter.ProcessOneMetadata(rdr);
                            }while (await rdr.NextResultAsync());
                        }
                    }
                    using (var cmd = cnn.CreateCommandSP(command))
                    {
                        SqlCommandBuilder.DeriveParameters(cmd);
                        dataWriter.SetTableParameters(cmd, data, prms);
                        using (var rdr = await cmd.ExecuteReaderAsync())
                        {
                            do
                            {
                                // metadata is not needed
                                while (await rdr.ReadAsync())
                                {
                                    dataReader.ProcessOneRecord(rdr);
                                }
                            }while (await rdr.NextResultAsync());
                        }
                    }
                }
                dataReader.PostProcess();
                return(dataReader.DataModel);
            }
        }