Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Maybe Orm is just one database management develop direction.

$
0
0

Ervery body knows that roslyn is open source.

We can write csharp code like template.It called magic sugar.

I want something like this:

var con=Models.DatabaseName.OpenConnection();
var us=con.Query("select * from users");
con.close();

Use reader.GetSchemaTable method.I can easily get all the fields.

The roslyn can create users class by itself.

public class Usesrs
		{
			public System.Int32 id;
			public System.String name;
			public System.String pwd;
			#region Write JsonString
			public override void WriteJson(System.IO.TextWriter tw)
			{
				tw.Write("{");
						tw.Write("\"id\":");
						tw.Write(id.ToString());
						tw.Write(",");
						tw.Write("\"name\":");
						if(name==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(name);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"pwd\":");
						if(pwd==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(pwd);
							tw.Write("\"");
						}
				tw.Write("}");
			}
			#endregion
		}

Also Create a new Class with code below:

var con = new MySql.Data.MySqlClient.MySqlConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["mysql"].ConnectionString);
			con.Open();
            	#region	var us;
			var us = new NFinal.List<Users>();
			var __queryAll_us_command__ = new MySql.Data.MySqlClient.MySqlCommand("select users.id,users.name,users.pwd from users",con);
			var __queryAll_us_reader__= __queryAll_us_command__.ExecuteReader();
			if (__queryAll_us_reader__.HasRows)
			{
				while (__queryAll_us_reader__.Read())
				{
					var __queryAll_us_temp__ = new __queryAll_us__();
					__queryAll_us_temp__.id = __queryAll_us_reader__.GetInt32(0);
					__queryAll_us_temp__.name =__queryAll_us_reader__.IsDBNull(1)?null: __queryAll_us_reader__.GetString(1);
					__queryAll_us_temp__.pwd =__queryAll_us_reader__.IsDBNull(2)?null: __queryAll_us_reader__.GetString(2);
					us.Add(__queryAll_us_temp__);
				}
			}
			__queryAll_us_reader__.Dispose();
			__queryAll_us_command__.Dispose();
	#endregion
            con.Close();

It's like  handwrite code.and it's fast. 

if csharp code editor support sql prompt.that will be more easy,faster and clear than orm.

when i use some parameters.I just write sql like this:

int id=1;
var us=con.Query("select * from users where Id=@id");


I had realize this generator.I think maybe sql is more better than orm if editor support sql prompt.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>