本文整理汇总了C#中IObjectInfo类的典型用法代码示例。如果您正苦于以下问题:C# IObjectInfo类的具体用法?C# IObjectInfo怎么用?C# IObjectInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IObjectInfo类属于命名空间,在下文中一共展示了IObjectInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildDeleteSqlQuery
/// <summary>
/// Builds an SqlQuery to delete the database record with the specified identifier for the type specified by the IObjectInfo.
/// </summary>
/// <param name="objectInfo">The object information.</param>
/// <param name="identifier">The identifier of the instance to delete.</param>
/// <returns>
/// The created <see cref="SqlQuery" />.
/// </returns>
public SqlQuery BuildDeleteSqlQuery(IObjectInfo objectInfo, object identifier)
{
if (objectInfo == null)
{
throw new ArgumentNullException("objectInfo");
}
string deleteCommand;
if (!this.deleteCommandCache.TryGetValue(objectInfo.ForType, out deleteCommand))
{
var deleteSqlQuery = new DeleteSqlBuilder(this.SqlCharacters)
.From(objectInfo)
.WhereEquals(objectInfo.TableInfo.IdentifierColumn.ColumnName, identifier)
.ToSqlQuery();
var newDeleteCommandCache = new Dictionary<Type, string>(this.deleteCommandCache);
newDeleteCommandCache[objectInfo.ForType] = deleteSqlQuery.CommandText;
this.deleteCommandCache = newDeleteCommandCache;
return deleteSqlQuery;
}
return new SqlQuery(deleteCommand, identifier);
}
示例2: CreateGetIdentifier
internal static Func<object, object> CreateGetIdentifier(IObjectInfo objectInfo)
{
var dynamicMethod = new DynamicMethod(
name: "MicroLite" + objectInfo.ForType.Name + "GetIdentifier",
returnType: typeof(object),
parameterTypes: new[] { typeof(object) }); // arg_0
var ilGenerator = dynamicMethod.GetILGenerator();
// var instance = ({Type})arg_0;
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Castclass, objectInfo.ForType);
// var identifier = instance.Id;
ilGenerator.Emit(OpCodes.Callvirt, objectInfo.TableInfo.IdentifierColumn.PropertyInfo.GetGetMethod());
// value = (object)identifier;
ilGenerator.EmitBoxIfValueType(objectInfo.TableInfo.IdentifierColumn.PropertyInfo.PropertyType);
// return identifier;
ilGenerator.Emit(OpCodes.Ret);
var getIdentifierValue = (Func<object, object>)dynamicMethod.CreateDelegate(typeof(Func<object, object>));
return getIdentifierValue;
}
示例3: BuildInsertCommandText
protected override string BuildInsertCommandText(IObjectInfo objectInfo)
{
if (objectInfo == null)
{
throw new ArgumentNullException("objectInfo");
}
var commandText = base.BuildInsertCommandText(objectInfo);
if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.Sequence)
{
var firstParenthesisIndex = commandText.IndexOf('(') + 1;
commandText = commandText.Insert(
firstParenthesisIndex,
this.SqlCharacters.EscapeSql(objectInfo.TableInfo.IdentifierColumn.ColumnName) + ",");
var secondParenthesisIndex = commandText.IndexOf('(', firstParenthesisIndex) + 1;
commandText = commandText.Insert(
secondParenthesisIndex,
"GEN_ID(" + objectInfo.TableInfo.IdentifierColumn.SequenceName + ", 1),");
}
if (objectInfo.TableInfo.IdentifierStrategy != IdentifierStrategy.Assigned)
{
commandText += " RETURNING " + objectInfo.TableInfo.IdentifierColumn.ColumnName;
}
return commandText;
}
示例4: From
internal IWhere From(IObjectInfo objectInfo)
{
this.InnerSql.Append(" FROM ");
this.AppendTableName(objectInfo);
return this;
}
示例5: Table
internal ISetOrWhere Table(IObjectInfo objectInfo)
{
this.AppendTableName(objectInfo);
this.InnerSql.Append(" SET ");
return this;
}
示例6: CreateGetInsertValues
internal static Func<object, SqlArgument[]> CreateGetInsertValues(IObjectInfo objectInfo)
{
var dynamicMethod = new DynamicMethod(
name: "MicroLite" + objectInfo.ForType.Name + "GetInsertValues",
returnType: typeof(SqlArgument[]),
parameterTypes: new[] { typeof(object) }, // arg_0
m: typeof(ObjectInfo).Module);
var ilGenerator = dynamicMethod.GetILGenerator();
ilGenerator.DeclareLocal(objectInfo.ForType); // loc_0 - {Type} instance;
ilGenerator.DeclareLocal(typeof(SqlArgument[])); // loc_1 - SqlArgument[] sqlArguments;
// instance = ({Type})arg_0;
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Castclass, objectInfo.ForType);
ilGenerator.Emit(OpCodes.Stloc_0);
// sqlArguments = new SqlArgument[count];
ilGenerator.EmitEfficientInt(objectInfo.TableInfo.InsertColumnCount);
ilGenerator.Emit(OpCodes.Newarr, typeof(SqlArgument));
ilGenerator.Emit(OpCodes.Stloc_1);
EmitGetPropertyValues(ilGenerator, objectInfo, c => c.AllowInsert);
// return sqlArguments;
ilGenerator.Emit(OpCodes.Ldloc_1);
ilGenerator.Emit(OpCodes.Ret);
var getInsertValues = (Func<object, SqlArgument[]>)dynamicMethod.CreateDelegate(typeof(Func<object, SqlArgument[]>));
return getInsertValues;
}
示例7: BuildInsertCommandText
protected override string BuildInsertCommandText(IObjectInfo objectInfo)
{
if (objectInfo == null)
{
throw new ArgumentNullException("objectInfo");
}
var commandText = base.BuildInsertCommandText(objectInfo);
if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.Sequence)
{
commandText = "DECLARE @@id " + GetSqlType(objectInfo.TableInfo.IdentifierColumn) + ";"
+ "SELECT @@id = NEXT VALUE FOR " + objectInfo.TableInfo.IdentifierColumn.SequenceName + ";"
+ commandText;
var firstParenthesisIndex = commandText.IndexOf('(') + 1;
commandText = commandText.Insert(
firstParenthesisIndex,
this.SqlCharacters.EscapeSql(objectInfo.TableInfo.IdentifierColumn.ColumnName) + ",");
var secondParenthesisIndex = commandText.IndexOf('(', firstParenthesisIndex) + 1;
commandText = commandText.Insert(
secondParenthesisIndex,
"@@id,");
}
return commandText;
}
示例8: BindSelect
/// <summary>
/// Binds the select query option to the SqlBuilder.
/// </summary>
/// <param name="selectQueryOption">The select query option.</param>
/// <param name="objectInfo">The IObjectInfo for the type to bind the select list for.</param>
/// <returns>The SqlBuilder after the select and from clauses have been added.</returns>
public static IWhereOrOrderBy BindSelect(SelectQueryOption selectQueryOption, IObjectInfo objectInfo)
{
if (objectInfo == null)
{
throw new ArgumentNullException("objectInfo");
}
if (selectQueryOption == null || (selectQueryOption.Properties.Count == 1 && selectQueryOption.Properties[0] == "*"))
{
return SqlBuilder.Select("*").From(objectInfo.ForType);
}
var columnNames = new string[selectQueryOption.Properties.Count];
int columnCount = 0;
for (int i = 0; i < selectQueryOption.Properties.Count; i++)
{
var property = selectQueryOption.Properties[i];
var column = objectInfo.TableInfo.GetColumnInfoForProperty(property);
if (column == null)
{
throw new ODataException(string.Format(CultureInfo.InvariantCulture, Messages.InvalidPropertyName, objectInfo.ForType.Name, property));
}
columnNames[columnCount++] = column.ColumnName;
}
return SqlBuilder.Select(columnNames).From(objectInfo.ForType);
}
示例9: ArgumentException
void IObjectManager.CreateObject(IObjectInfo objInfo)
{
var variableInfo = objInfo as VariableInfo;
if (variableInfo == null)
throw new ArgumentException();
DefineVariable(variableInfo);
}
示例10: Encode
public void Encode(ByteArrayOutputStream os, IObjectInfo info)
{
PrimitiveCodec.WriteLong(os, info.GetInternalID());
long sourceDatabaseId = ((FrozenObjectInfo)info).SourceDatabaseId(this._enclosing
.Transaction());
PrimitiveCodec.WriteLong(os, sourceDatabaseId);
PrimitiveCodec.WriteLong(os, ((FrozenObjectInfo)info).UuidLongPart());
PrimitiveCodec.WriteLong(os, info.GetCommitTimestamp());
}
示例11: AssertInfosAreConsistent
private void AssertInfosAreConsistent(long[] ids, IObjectInfo[] infos)
{
for (var i = 0; i < infos.Length; i++)
{
var info = Db().GetObjectInfo(Db().GetByID(ids[i]));
Assert.AreEqual(info.GetInternalID(), infos[i].GetInternalID());
Assert.AreEqual(info.GetUUID().GetLongPart(), infos[i].GetUUID().GetLongPart());
Assert.AreSame(info.GetObject(), infos[i].GetObject());
}
}
示例12: AlterObject
public static void AlterObject(this IQueryContext context, IObjectInfo objectInfo)
{
if (objectInfo == null)
throw new ArgumentNullException("objectInfo");
if (!context.UserCanAlterObject(objectInfo.ObjectType, objectInfo.FullName))
throw new MissingPrivilegesException(context.UserName(), objectInfo.FullName, Privileges.Alter);
context.Session().AlterObject(objectInfo);
}
示例13: BuildInsertCommandText
protected override string BuildInsertCommandText(IObjectInfo objectInfo)
{
var commandText = base.BuildInsertCommandText(objectInfo);
if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.DbGenerated)
{
commandText += " RETURNING " + objectInfo.TableInfo.IdentifierColumn.ColumnName;
}
return commandText;
}
示例14: AppendTableName
/// <summary>
/// Appends the table name to the inner sql.
/// </summary>
/// <param name="objectInfo">The object information.</param>
protected void AppendTableName(IObjectInfo objectInfo)
{
if (!string.IsNullOrEmpty(objectInfo.TableInfo.Schema))
{
this.InnerSql.Append(this.sqlCharacters.LeftDelimiter)
.Append(objectInfo.TableInfo.Schema)
.Append(this.sqlCharacters.RightDelimiter)
.Append('.');
}
this.AppendTableName(objectInfo.TableInfo.Name);
}
示例15: AssertGeneration
private void AssertGeneration(IObjectInfo objectInfo, bool expectGeneration)
{
if (expectGeneration)
{
Assert.IsNotNull(objectInfo.GetUUID());
}
else
{
Assert.IsNull(objectInfo.GetUUID());
Assert.AreEqual(0L, objectInfo.GetCommitTimestamp());
}
}