Project file:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="System.Data.SqlClient" Version="4.3.0" /> <PackageReference Include="Dapper" Version="1.50.2" /> <PackageReference Include="Newtonsoft.Json" Version="*" /> <PackageReference Include="System.IO.FileSystem" Version="*" /> <PackageReference Include="SapientGuardian.MySql.Data" Version="*" /> </ItemGroup> </Project>
Program.cs:
using System; using System.Linq; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using Dapper; using MySql.Data.MySqlClient; using System.IO; using static System.Console; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { var list = new List<string>(); list.Add("Shawn Lin"); list.Add($"Current Date: {DateTime.Now:yyyyMMdd}"); list.ForEach(item => { WriteLine(item); }); Console.WriteLine("Hello World!"); try{ //var connection = new SqlConnection("server=.;database=DB1;integrated security=sspi;"); var connection = new MySqlConnection("server=ali.centos.NOT VALID.com;database=DB1;uid=tuotuo;pwd=test!;charset=utf8;"); //var data = connection.Query<int>("select 1501 as dat union select 2000;").ToList().First(); var data = connection.Query<Train>("select * from trains"); WriteLine(data); var data2 = connection.Query<Train>("GetTrainsFromStagingTable", new {p_is_active= true}, commandType: CommandType.StoredProcedure); WriteLine(data2.Count()); data2.ToList().ForEach(row => { WriteLine($"{row.train_key} {row.train_code} {row.begin_station} {row.end_station} {row.is_active}"); //File.AppendAllText(@"c: mpfilesaaaaa.txt", $"{row.train_key} {row.train_code} {row.begin_station} {row.end_station} {row.is_active}"); }); }catch(Exception ex){ WriteLine(ex.Message); } } } public class Train{ public int train_key {get;set;} public string train_code {get;set;} public string begin_station {get;set;} public bool is_active {get;set;} public string end_station {get;set;} } }