public static object InsertInto(this object o, string table, ConnectionProfile connectionProfile = null) { if (connectionProfile == null) connectionProfile = new ConnectionProfile(); DynamicRepository dynamicModel = new DynamicRepository(connectionProfile, table, "Id"); return dynamicModel.Insert(o); }
void saving_dynamic_params() { before = () => { seed = new Seed(); seed.PurgeDb(); seed.CreateTable("Blogs", new dynamic[] { new { Id = "int", Identity = true, PrimaryKey = true }, new { Title = "nvarchar(255)" } }).ExecuteNonQuery(); nameValueCollection.Add("Title", "Some Title"); }; it["persists saveable values to the database"] = () => { var blogs = new DynamicRepository("Blogs"); var blogId = blogs.Insert(asDynamic); var blog = blogs.Single(blogId); (blog.Title as string).should_be("Some Title"); }; }
void mass_assignment() { before = () => { seed = new Seed(); seed.PurgeDb(); seed.CreateTable("Users", new dynamic[] { new { Id = "int", Identity = true, PrimaryKey = true }, new { Name = "nvarchar(255)" }, new { IsAdmin = "bit", Default = false } }).ExecuteNonQuery(); nameValueCollection.Add("Name", "John"); nameValueCollection.Add("IsAdmin", "true"); }; it["allows the ability to exclude fields"] = () => { var users = new DynamicRepository("Users"); var userId = users.Insert(asDynamic.Exclude("IsAdmin")); var user = users.Single(userId); (user.Name as string).should_be("John"); ((bool)user.IsAdmin).should_be(false); }; it["allows the ability to select fields"] = () => { var users = new DynamicRepository("Users"); var userId = users.Insert(asDynamic.Select("Name")); var user = users.Single(userId); (user.Name as string).should_be("John"); ((bool)user.IsAdmin).should_be(false); }; }