本文整理汇总了C#中IDbConnection.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.SingleOrDefault方法的具体用法?C# IDbConnection.SingleOrDefault怎么用?C# IDbConnection.SingleOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.SingleOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGroup
static void CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, string[] nodes, IDbConnection ctx, IDbTransaction txn,
string chatPrefix = null,
string chatSuffix = null)
#endif
{
#if ENTITY_FRAMEWORK_7
var grp = new Group()
{
Name = name,
ApplyToGuests = guest,
Parent = parent,
Chat_Red = r,
Chat_Green = g,
Chat_Blue = b,
Chat_Prefix = chatPrefix,
Chat_Suffix = chatSuffix
};
ctx.Groups.Add(grp);
ctx.SaveChanges(); //Save to get the ID
foreach (var nd in nodes)
{
var node = ctx.Nodes.SingleOrDefault(x => x.Node == nd && x.Permission == Permission.Permitted);
if (node == null)
{
ctx.Nodes.Add(node = new NodePermission()
{
Node = nd,
Permission = Permission.Permitted
});
ctx.SaveChanges();
}
ctx.GroupNodes.Add(new GroupNode()
{
GroupId = grp.Id,
NodeId = node.Id
});
}
ctx.SaveChanges();
#elif DAPPER
var grp = new Group()
{
Name = name,
ApplyToGuests = guest,
Parent = parent,
Chat_Red = r,
Chat_Green = g,
Chat_Blue = b,
Chat_Prefix = chatPrefix,
Chat_Suffix = chatSuffix
};
grp.Id = ctx.Insert(grp, txn);
foreach (var nd in nodes)
{
var node = ctx.SingleOrDefault<PermissionNode>(new { Node = nd, Permission = Permission.Permitted }, transaction: txn);
if (node == null)
{
node = new PermissionNode()
{
Node = nd,
Permission = Permission.Permitted
};
node.Id = ctx.Insert(node, transaction: txn);
}
ctx.Insert(new GroupNode()
{
GroupId = grp.Id,
NodeId = node.Id
}, transaction: txn);
}
#endif
}