本文整理汇总了C#中SerializationContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationContext.SaveChanges方法的具体用法?C# SerializationContext.SaveChanges怎么用?C# SerializationContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerializationContext
的用法示例。
在下文中一共展示了SerializationContext.SaveChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeNullableObjectInOutTest
public void SerializeNullableObjectInOutTest()
{
var values = new NullableTypes
{
aASCIIString = "hello world!",
aBlob = new byte[] { 1, 2, 3, 4 },
aBool = true,
aDecimal = decimal.MaxValue / 2,
aDouble = 1.234,
aFloat = 5.789f,
aInet = new IPAddress(new byte[] { 127, 0, 0, 1 }),
aInt = 10,
aLong = 56789012456,
aTextString = "some other text with \u005C unicode",
aVarcharString = "some other varchar with \u005C unicode",
aTimeUUID = DateTime.Now.GenerateTimeBasedGuid(),
aUUID = Guid.NewGuid(),
aTimestamp = DateTime.Now,
aVarint = new BigInteger(12345678901234),
aList = new List<string> { "string 1", "string 2" },
aSet = new HashSet<int> { 1, 3, 3 },
aMap =
new Dictionary<long, string> { { 1, "value 1" }, { 2, "value 2" }, { 3, "value 3" } },
};
using (var context = new SerializationContext())
{
context.NullableTypes.Add(values);
context.SaveChanges();
}
using (var context = new SerializationContext())
{
var result = context.NullableTypes.FirstOrDefault();
Assert.IsNotNull(result);
Assert.AreEqual(values.aASCIIString, result.aASCIIString);
Assert.AreEqual(values.aVarcharString, result.aVarcharString);
Assert.AreEqual(values.aVarint, result.aVarint);
Assert.AreEqual(values.aTextString, result.aTextString);
Assert.AreEqual(values.aBool, result.aBool);
Assert.AreEqual(values.aDecimal, result.aDecimal);
Assert.AreEqual(values.aDouble, result.aDouble);
Assert.AreEqual(values.aFloat, result.aFloat);
Assert.AreEqual(values.aInet, result.aInet);
Assert.AreEqual(values.aInt, result.aInt);
Assert.AreEqual(values.aLong, result.aLong);
Assert.AreEqual(values.aTimeUUID, result.aTimeUUID);
Assert.AreEqual(values.aUUID, result.aUUID);
Assert.IsTrue(result.aBlob.SequenceEqual(values.aBlob));
Assert.IsTrue(result.aList.SequenceEqual(values.aList));
Assert.IsTrue(result.aSet.SequenceEqual(values.aSet));
}
}
示例2: SerializeNullableObjectInOutDefaultsTest
public void SerializeNullableObjectInOutDefaultsTest()
{
var values = new NullableTypes { aInt = 10 };
using (var context = new SerializationContext())
{
context.NullableTypes.Add(values);
context.SaveChanges();
}
using (var context = new SerializationContext())
{
var result = context.NullableTypes.FirstOrDefault();
Assert.IsNotNull(result);
Assert.IsNull(result.aASCIIString);
Assert.IsNull(result.aVarcharString);
Assert.IsNull(result.aVarint);
Assert.IsNull(result.aTextString);
Assert.IsNull(result.aBool);
Assert.IsNull(result.aDecimal);
Assert.IsNull(result.aDouble);
Assert.IsNull(result.aFloat);
Assert.IsNull(result.aInet);
Assert.IsNull(result.aLong);
Assert.IsNull(result.aTimeUUID);
Assert.IsNull(result.aUUID);
Assert.IsNull(result.aBlob);
Assert.IsNull(result.aList);
Assert.IsNull(result.aSet);
Assert.IsNull(result.aMap);
}
}
示例3: SerializeObjectInOutDefaultsTest
public void SerializeObjectInOutDefaultsTest()
{
var values = new Types { aInt = 3, aTimeUUID = TimeGuid.Default };
using (var context = new SerializationContext())
{
context.Types.Add(values);
context.SaveChanges();
}
using (var context = new SerializationContext())
{
var result = context.Types.FirstOrDefault();
Assert.IsNotNull(result);
Assert.AreEqual(result.aASCIIString, default(string));
Assert.AreEqual(result.aVarcharString, default(string));
Assert.AreEqual(result.aVarint, default(BigInteger));
Assert.AreEqual(result.aTextString, default(string));
Assert.AreEqual(result.aBool, default(bool));
Assert.AreEqual(result.aDecimal, default(decimal));
Assert.AreEqual(result.aDouble, default(double));
Assert.AreEqual(result.aFloat, default(float));
Assert.AreEqual(result.aInet, default(IPAddress));
Assert.AreEqual(result.aLong, default(long));
Assert.AreEqual(result.aTimeUUID, TimeGuid.Default);
Assert.AreEqual(result.aUUID, default(Guid));
Assert.AreEqual(result.aBlob, default(byte[]));
Assert.AreEqual(result.aList, default(List<string>));
Assert.AreEqual(result.aSet, default(HashSet<int>));
Assert.AreEqual(result.aMap, default(Dictionary<long, string>));
}
}