本文整理汇总了C#中IDbContext.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IDbContext.Execute方法的具体用法?C# IDbContext.Execute怎么用?C# IDbContext.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbContext
的用法示例。
在下文中一共展示了IDbContext.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSchema
public static void CreateSchema(IDbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
context.Execute(new Query(@"
CREATE TABLE FEATURE_CONTEXTS (
Id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
Name nvarchar(254) NOT NULL
)"));
context.Execute(new Query(@"
CREATE TABLE FEATURE_EXCEPTIONS (
Id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
Contents nvarchar(254) NOT NULL
)"));
context.Execute(new Query(@"
CREATE TABLE FEATURES (
Id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
Name nvarchar(254) NOT NULL,
Context_Id integer NOT NULL,
FOREIGN KEY (Context_Id)
REFERENCES FEATURE_CONTEXTS (Id)
ON UPDATE CASCADE ON DELETE CASCADE
)"));
context.Execute(new Query(@"
CREATE TABLE FEATURE_ENTRIES (
Id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
Details nvarchar(254) NOT NULL,
Created_At datetime NOT NULL,
Feature_Id integer NOT NULL,
FOREIGN KEY (Feature_Id)
REFERENCES FEATURES (Id)
ON UPDATE CASCADE ON DELETE CASCADE
)"));
context.Execute(new Query(@"
CREATE TABLE FEATURE_EXCEPTION_ENTRIES (
Id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
Exception_Id integer NOT NULL,
Created_At datetime NOT NULL,
Feature_Id integer NOT NULL,
FOREIGN KEY (Feature_Id)
REFERENCES FEATURES (Id)
ON UPDATE CASCADE ON DELETE CASCADE
FOREIGN KEY (Exception_Id)
REFERENCES FEATURE_EXCEPTIONS (Id)
ON UPDATE CASCADE ON DELETE CASCADE
)"));
}
示例2: CreateUser
private void CreateUser(string database, string loginId, IDbContext context)
{
context.Connection.ChangeDatabase("master");
context.Execute("CREATE LOGIN [{1}] WITH PASSWORD=N'123456', DEFAULT_DATABASE=[{0}], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
.Fmt(database, loginId))
.ToNonQuery();
context.Connection.ChangeDatabase(database);
context.Execute("CREATE USER [{0}] FOR LOGIN [{0}]".Fmt(loginId))
.ToNonQuery();
context.Execute("EXEC sp_addrolemember N'db_owner', N'{0}'".Fmt(loginId))
.ToNonQuery();
context.Connection.ChangeDatabase("master");
}
示例3: UpdateUser
public static void UpdateUser(IDbContext context, long userId, long versionId)
{
var sqlParams = new[]
{
new QueryParameter(@"@ID", userId),
new QueryParameter(@"@REPLICATED_AT", DateTime.Now),
new QueryParameter(@"@VERSION", versionId),
};
context.Execute(new Query(@"UPDATE FEATURE_USERS SET REPLICATED_AT = @REPLICATED_AT, VERSION_ID = @VERSION WHERE ID = @ID", sqlParams));
}
示例4: InsertFeatureEntry
public static void InsertFeatureEntry(IDbContext context, IEnumerable<DbFeatureEntryRow> featureEntryRows, long userId, long versionId, Dictionary<int, long> featuresMap)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (featureEntryRows == null) throw new ArgumentNullException(nameof(featureEntryRows));
if (featuresMap == null) throw new ArgumentNullException(nameof(featuresMap));
var buffer = new StringBuilder(@"INSERT INTO FEATURE_ENTRIES(DETAILS, CREATED_AT, FEATURE_ID, USER_ID, VERSION_ID) VALUES ");
var addComma = false;
foreach (var e in featureEntryRows)
{
if (addComma)
{
buffer.Append(',');
}
buffer.Append('(');
buffer.Append('\'');
buffer.Append(e.Details);
buffer.Append('\'');
buffer.Append(',');
buffer.Append('\'');
buffer.Append(e.CreatedAt.ToString(SqliteFullDateTimeFormat));
buffer.Append('\'');
buffer.Append(',');
buffer.Append(featuresMap[e.FeatureId]);
buffer.Append(',');
buffer.Append(userId);
buffer.Append(',');
buffer.Append(versionId);
buffer.Append(')');
addComma = true;
}
context.Execute(new Query(buffer.ToString()));
}
示例5: DropSchema
public static void DropSchema(IDbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
foreach (var name in new[]
{
@"FEATURE_EXCEPTIONS_EXCLUDED",
@"FEATURE_EXCEPTION_ENTRIES",
@"FEATURE_ENTRIES",
@"FEATURE_USERS",
@"FEATURES",
@"FEATURE_CONTEXTS",
@"FEATURE_VERSIONS",
@"FEATURE_EXCEPTIONS"
})
{
context.Execute(new Query(@"DROP TABLE " + name));
}
}
示例6: GetVersions
public static IEnumerable<VersionRow> GetVersions(IDbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
var query = @"SELECT ID, NAME FROM FEATURE_VERSIONS ORDER BY NAME";
var versions = context.Execute(new Query<VersionRow>(query, r => new VersionRow(r.GetInt64(0), r.GetString(1))));
versions.Insert(0, new VersionRow(-1, @"All"));
return versions;
}
示例7: InsertFeatureEntry
public static void InsertFeatureEntry(IDbContext context, int featureId, string details)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (details == null) throw new ArgumentNullException(nameof(details));
// Set parameters values
InsertClientFeatureEntryQuery.Parameters[0].Value = details;
InsertClientFeatureEntryQuery.Parameters[1].Value = DateTime.Now;
InsertClientFeatureEntryQuery.Parameters[2].Value = featureId;
// Insert the record
context.Execute(InsertClientFeatureEntryQuery);
}
示例8: GetNewId
private static int GetNewId(IDbContext context)
{
return (int)context.Execute(GetNewIdQuery).FirstOrDefault();
}
示例9: InsertExceptionEntry
public static void InsertExceptionEntry(IDbContext context, int featureId, int exceptionId)
{
if (context == null) throw new ArgumentNullException(nameof(context));
InsertExceptionEntryQuery.Parameters[0].Value = exceptionId;
InsertExceptionEntryQuery.Parameters[1].Value = DateTime.Now;
InsertExceptionEntryQuery.Parameters[2].Value = featureId;
context.Execute(InsertExceptionEntryQuery);
}
示例10: InsertFeature
public static int InsertFeature(IDbContext context, string name, long contextId)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (name == null) throw new ArgumentNullException(nameof(name));
// Set parameters values
InsertFeatureQuery.Parameters[0].Value = name;
InsertFeatureQuery.Parameters[1].Value = contextId;
context.Execute(InsertFeatureQuery);
return GetNewId(context);
}
示例11: InsertException
public static int InsertException(IDbContext context, string contents)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (contents == null) throw new ArgumentNullException(nameof(contents));
// Set parameters values
InsertExceptionQuery.Parameters[0].Value = contents;
context.Execute(InsertExceptionQuery);
return GetNewId(context);
}
示例12: GetOrCreateException
public static int GetOrCreateException(IDbContext context, string contents)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (contents == null) throw new ArgumentNullException(nameof(contents));
GetExceptionQuery.Parameters[0].Value = contents;
var exceptions = context.Execute(GetExceptionQuery);
if (exceptions.Count > 0)
{
return exceptions[0];
}
return InsertException(context, contents);
}
示例13: GetFeatures
public static List<DbFeatureRow> GetFeatures(IDbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
return context.Execute(GetFeaturesQuery);
}
示例14: GetData
public static ClientData GetData(IDbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
var contextRows = context.Execute(GetContextsQuery);
var exceptionRows = context.Execute(GetDbFeatureExceptionsRowQuery);
var featureRows = context.Execute(GetFeaturesQuery);
var featureEntryRows = context.Execute(GetFeatureEntriesQuery);
var exceptionEntryRows = context.Execute(GetDbFeatureExceptionEntryRowQuery);
return new ClientData(contextRows, exceptionRows, featureRows, featureEntryRows, exceptionEntryRows);
}
示例15: ExecuteInsert
public static long ExecuteInsert(IDbContext context, Query query)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (query == null) throw new ArgumentNullException(nameof(query));
// Insert the record
context.Execute(query);
return GetNewId(context);
}