コード例 #1
0
ファイル: Exporter.cs プロジェクト: fjiang2/sqlcon
        public void ExportLinq2SQLClass()
        {
            string path = cmd.OutputPath(ConfigKey._GENERATOR_L2S_PATH, $"{ConfigurationEnvironment.MyDocuments}\\dc");
            string ns   = cmd.GetValue("ns", ConfigKey._GENERATOR_L2S_NS, "Sys.DataModel.L2s");

            if (tname != null)
            {
                var builder = new Linq2SQLClassBuilder(cmd, tname)
                {
                };
                builder.SetNamespace(ns);

                string file = builder.WriteFile(path);
                cout.WriteLine("code generated on {0}", file);
            }
            else if (dname != null)
            {
                TableName[] tnames = getTableNames(cmd);
                foreach (var tname in tnames)
                {
                    var builder = new Linq2SQLClassBuilder(cmd, tname)
                    {
                    };
                    builder.SetNamespace(ns);

                    string file = builder.WriteFile(path);
                    cout.WriteLine("code generated on {0}", file);
                }
            }
            else
            {
                cerr.WriteLine("warning: table or database is not seleted");
            }

            TableSchemaCache.Clear();
        }
コード例 #2
0
ファイル: Exporter.cs プロジェクト: fjiang2/sqlcon
        public void ExportLinq2SQLClass(Command cmd)
        {
            string path = cfg.GetValue<string>("l2s.path", $"{Configuration.MyDocuments}\\dc");
            string ns = cmd.GetValue("ns") ?? cfg.GetValue<string>("l2s.ns", "Sys.DataModel.L2s");
            Dictionary<TableName, TableSchema> schemas = new Dictionary<TableName, TableSchema>();

            if (tname != null)
            {
                var builder = new Linq2SQLClassBuilder(ns, cmd, tname, schemas);
                string file = builder.WriteFile(path);
                stdio.WriteLine("code generated on {0}", file);
            }
            else if (dname != null)
            {
                TableName[] tnames;
                if (cmd.wildcard != null)
                {
                    var md = new MatchedDatabase(dname, cmd.wildcard, new string[] { });
                    tnames = md.MatchedTableNames;
                    if (tnames.Length == 0)
                    {
                        stdio.ErrorFormat("warning: no table is matched");
                        return;
                    }
                }
                else
                {
                    tnames = dname.GetTableNames();
                }

                foreach (var tname in tnames)
                {
                    var builder = new Linq2SQLClassBuilder(ns, cmd, tname, schemas);
                    string file = builder.WriteFile(path);
                    stdio.WriteLine("code generated on {0}", file);
                }

                return;
            }
            else
            {
                stdio.ErrorFormat("warning: table or database is not seleted");
            }
        }