本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Table.Entities.ComplexEntity.WriteEntity方法的典型用法代码示例。如果您正苦于以下问题:C# ComplexEntity.WriteEntity方法的具体用法?C# ComplexEntity.WriteEntity怎么用?C# ComplexEntity.WriteEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Table.Entities.ComplexEntity
的用法示例。
在下文中一共展示了ComplexEntity.WriteEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTableRegionalQueryOnSupportedTypesAsync
private async Task DoTableRegionalQueryOnSupportedTypesAsync(TablePayloadFormat format)
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
CloudTableClient client = GenerateCloudTableClient();
client.DefaultRequestOptions.PayloadFormat = format;
CloudTable table = client.GetTableReference(GenerateRandomTableName());
await table.CreateAsync();
try
{
// Setup
TableBatchOperation batch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
DynamicTableEntity middleRef = null;
for (int m = 0; m < 100; m++)
{
ComplexEntity complexEntity = new ComplexEntity();
complexEntity.String = string.Format("{0:0000}", m);
complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m };
complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m };
complexEntity.Bool = m % 2 == 0 ? true : false;
complexEntity.BoolPrimitive = m % 2 == 0 ? true : false;
complexEntity.Double = m + ((double)m / 100);
complexEntity.DoublePrimitive = m + ((double)m / 100);
complexEntity.Int32 = m;
complexEntity.IntegerPrimitive = m;
complexEntity.Int64 = (long)int.MaxValue + m;
complexEntity.LongPrimitive = (long)int.MaxValue + m;
complexEntity.Guid = Guid.NewGuid();
DynamicTableEntity dynEnt = new DynamicTableEntity(pk, string.Format("{0:0000}", m));
dynEnt.Properties = complexEntity.WriteEntity(null);
batch.Insert(dynEnt);
if (m == 50)
{
middleRef = dynEnt;
}
// Add delay to make times unique
await Task.Delay(100);
}
await table.ExecuteBatchAsync(batch);
// 1. Filter on String
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterCondition("String", QueryComparisons.GreaterThanOrEqual, "0050"), 50);
// 2. Filter on Guid
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForGuid("Guid", QueryComparisons.Equal, middleRef.Properties["Guid"].GuidValue.Value), 1);
// 3. Filter on Long
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForLong("Int64", QueryComparisons.GreaterThanOrEqual,
middleRef.Properties["LongPrimitive"].Int64Value.Value), 50);
ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("LongPrimitive",
QueryComparisons.GreaterThanOrEqual, middleRef.Properties["LongPrimitive"].Int64Value.Value), 50);
// 4. Filter on Double
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForDouble("Double", QueryComparisons.GreaterThanOrEqual,
middleRef.Properties["Double"].DoubleValue.Value), 50);
ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("DoublePrimitive",
QueryComparisons.GreaterThanOrEqual, middleRef.Properties["DoublePrimitive"].DoubleValue.Value), 50);
// 5. Filter on Integer
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForInt("Int32", QueryComparisons.GreaterThanOrEqual,
middleRef.Properties["Int32"].Int32Value.Value), 50);
ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("IntegerPrimitive",
QueryComparisons.GreaterThanOrEqual, middleRef.Properties["IntegerPrimitive"].Int32Value.Value), 50);
// 6. Filter on Date
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForDate("DateTimeOffset", QueryComparisons.GreaterThanOrEqual,
middleRef.Properties["DateTimeOffset"].DateTimeOffsetValue.Value), 50);
// 7. Filter on Boolean
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForBool("Bool", QueryComparisons.Equal, middleRef.Properties["Bool"].BooleanValue.Value), 50);
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForBool("BoolPrimitive", QueryComparisons.Equal, middleRef.Properties["BoolPrimitive"].BooleanValue.Value),
50);
// 8. Filter on Binary
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.Equal, middleRef.Properties["Binary"].BinaryValue), 1);
ExecuteQueryAndAssertResults(table,
TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.Equal,
middleRef.Properties["BinaryPrimitive"].BinaryValue), 1);
//.........这里部分代码省略.........
示例2: TableEdmTypeCheck
public void TableEdmTypeCheck()
{
CloudTableClient tableClient = GenerateCloudTableClient();
string pk = Guid.NewGuid().ToString();
DynamicTableEntity sendEnt = new DynamicTableEntity();
sendEnt.PartitionKey = pk;
sendEnt.RowKey = Guid.NewGuid().ToString();
ComplexEntity ent = new ComplexEntity();
ent.String = null;
sendEnt.Properties = ent.WriteEntity(null);
string value = sendEnt.Properties["String"].StringValue;
Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType);
sendEnt.Properties["String"].StringValue = "helloworld";
Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType);
sendEnt.Properties["String"].StringValue = null;
Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType);
ent.Binary = null;
sendEnt.Properties = ent.WriteEntity(null);
byte[] binaryValue = sendEnt.Properties["Binary"].BinaryValue;
Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType);
sendEnt.Properties["Binary"].BinaryValue = new byte[] { 1, 2 };
Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType);
sendEnt.Properties["Binary"].BinaryValue = null;
Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType);
ent.DateTimeN = null;
sendEnt.Properties = ent.WriteEntity(null);
DateTime? dateTimeValue = sendEnt.Properties["DateTimeN"].DateTime;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType);
sendEnt.Properties["DateTimeN"].DateTime = DateTime.Now;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType);
sendEnt.Properties["DateTimeN"].DateTime = null;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType);
ent.DateTimeOffsetN = null;
sendEnt.Properties = ent.WriteEntity(null);
DateTimeOffset? dateTimeOffsetValue = sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType);
sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue = DateTimeOffset.Now;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType);
sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue = null;
Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType);
ent.DoubleN = null;
sendEnt.Properties = ent.WriteEntity(null);
double? doubleValue = sendEnt.Properties["DoubleN"].DoubleValue;
Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType);
sendEnt.Properties["DoubleN"].DoubleValue = 1234.5678;
Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType);
sendEnt.Properties["DoubleN"].DoubleValue = null;
Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType);
ent.GuidN = null;
sendEnt.Properties = ent.WriteEntity(null);
Guid? guidValue = sendEnt.Properties["GuidN"].GuidValue;
Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType);
sendEnt.Properties["GuidN"].GuidValue = Guid.NewGuid();
Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType);
sendEnt.Properties["GuidN"].GuidValue = null;
Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType);
ent.Int32N = null;
sendEnt.Properties = ent.WriteEntity(null);
int? intValue = sendEnt.Properties["Int32N"].Int32Value;
Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType);
sendEnt.Properties["Int32N"].Int32Value = 123;
Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType);
sendEnt.Properties["Int32N"].Int32Value = null;
Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType);
ent.LongPrimitiveN = null;
sendEnt.Properties = ent.WriteEntity(null);
long? longValue = sendEnt.Properties["LongPrimitiveN"].Int64Value;
Assert.AreEqual(EdmType.Int64, sendEnt.Properties["LongPrimitiveN"].PropertyType);
//.........这里部分代码省略.........
示例3: TableEntityCompiledVSReflectionSerializationEqualityTest
public void TableEntityCompiledVSReflectionSerializationEqualityTest()
{
string pk = Guid.NewGuid().ToString();
string rk = Guid.NewGuid().ToString();
ComplexEntity sendEnt = new ComplexEntity(pk, rk);
sendEnt.Binary = new Byte[] { 5, 6, 7, 8 };
sendEnt.BinaryNull = null;
sendEnt.BinaryPrimitive = new byte[] { 5, 6, 7, 8 };
sendEnt.Bool = true;
sendEnt.BoolN = true;
sendEnt.BoolNull = null;
sendEnt.BoolPrimitive = true;
sendEnt.BoolPrimitiveN = true;
sendEnt.BoolPrimitiveNull = null;
sendEnt.DateTime = DateTime.UtcNow.AddMinutes(1);
sendEnt.DateTimeN = DateTime.UtcNow.AddMinutes(1);
sendEnt.DateTimeNull = null;
sendEnt.DateTimeOffset = DateTimeOffset.Now.AddMinutes(1);
sendEnt.DateTimeOffsetN = DateTimeOffset.Now.AddMinutes(1);
sendEnt.DateTimeOffsetNull = null;
sendEnt.Double = (Double)5678.5678;
sendEnt.DoubleN = (Double)5678.5678;
sendEnt.DoubleNull = null;
sendEnt.DoublePrimitive = (double)5678.5678;
sendEnt.DoublePrimitiveN = (double)5678.5678;
sendEnt.DoublePrimitiveNull = null;
sendEnt.Guid = Guid.NewGuid();
sendEnt.GuidN = Guid.NewGuid();
sendEnt.GuidNull = null;
sendEnt.Int32 = 5678;
sendEnt.Int32N = 5678;
sendEnt.Int32Null = null;
sendEnt.Int64 = (long)5678;
sendEnt.Int64N = (long)5678;
sendEnt.Int64Null = null;
sendEnt.IntegerPrimitive = 5678;
sendEnt.IntegerPrimitiveN = 5678;
sendEnt.IntegerPrimitiveNull = null;
sendEnt.LongPrimitive = 5678;
sendEnt.LongPrimitiveN = 5678;
sendEnt.LongPrimitiveNull = null;
sendEnt.String = "ResetTestTotested";
TableEntity.DisableCompiledSerializers = true;
var reflectionDict = sendEnt.WriteEntity(null);
Assert.IsNull(sendEnt.CompiledWrite);
TableEntity.DisableCompiledSerializers = false;
var compiledDict = sendEnt.WriteEntity(null);
Assert.IsNotNull(sendEnt.CompiledWrite);
// Assert Serialized Dictionaries are the same
Assert.AreEqual(reflectionDict.Count, compiledDict.Count);
foreach (var kvp in reflectionDict)
{
Assert.IsTrue(compiledDict.ContainsKey(kvp.Key));
Assert.AreEqual(reflectionDict[kvp.Key], compiledDict[kvp.Key]);
}
}
示例4: ReflectionBasedSerializationTest
public void ReflectionBasedSerializationTest()
{
ComplexEntity ent = new ComplexEntity();
ComplexEntity secondEnt = new ComplexEntity();
secondEnt.ReadEntity(ent.WriteEntity(null), null);
ComplexEntity.AssertEquality(ent, secondEnt);
}