本文整理汇总了C#中Massive.DynamicRepository.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicRepository.Insert方法的具体用法?C# DynamicRepository.Insert怎么用?C# DynamicRepository.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Massive.DynamicRepository
的用法示例。
在下文中一共展示了DynamicRepository.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertInto
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);
}
示例2: saving_dynamic_params
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");
};
}
示例3: mass_assignment
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);
};
}