Answers for "send properties of class to dapper"

C#
0

send properties of class to dapper

class Program
    {
        static void Main(string[] args)
        {
            var usr = new User()
            {

                Email = "testmail",
                Name = "testname"
            };

            var connection = System.Configuration.ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString;
            using (IDbConnection dbConnection = new SqlConnection(connection))
            {
            dbConnection.Open();
                long insert = dbConnection.Insert<User>(usr);
            }
        }
    }

    [Table("[User]")]
    public class User
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }

    }
Posted by: Guest on December-30-2020

C# Answers by Framework

Browse Popular Code Answers by Language