/// <summary> /// Сохраняет запись /// </summary> /// <param name="entry">Entry.</param> protected override void SaveEntry(GuestbookEntry entry) { using (var db = new DbManager()) { var dbEntry = new DbGuestbookEntry (); dbEntry.Message = entry.Message; var dbUser = db.GetTable<DbGuestbookUser>().SingleOrDefault (u => u.Name == entry.User); if (dbUser == null) { dbUser = new DbGuestbookUser { Name = entry.User }; dbUser.Id = Convert.ToInt32(db.InsertWithIdentity (dbUser)); } dbEntry.UserId = dbUser.Id; dbEntry.Id = Convert.ToInt32(db.InsertWithIdentity(dbEntry)); } }
public void TestDataTypeTestInsertWithIdentity() { using (DbManager db = new DbManager()) { var dt = new DataTypeTest2 { Binary_ = new byte[2] { 1, 2 }, #if !ORACLE Boolean_ = true, Guid_ = Guid.Empty, #endif Byte_ = 250, Bytes_ = new byte[] { 2, 1 }, DateTime_ = DateTime.Now, Decimal_ = 9876543210.0m, Double_ = 12345.67890, Int16_ = 12345, Int32_ = 1234567890, Int64_ = 1234567890123456789, Money_ = 99876543210.0m, Single_ = 1234.0f, String_ = "Crazy Frog", Char_ = 'F', SByte_ = 123, //UInt16_ = 65432, //UInt32_ = 4000000000, //UInt64_ = 12345678901234567890, #if !SQLCE Stream_ = new MemoryStream(5), Xml_ = new XmlTextReader(new StringReader("<xml/>")), XmlDoc_ = new XmlDocument() #endif }; #if !SQLCE string innerxml = "<root><sql id=\"2\">Other Verbiage</sql></root>"; dt.XmlDoc_.LoadXml(innerxml); #endif var id = Convert.ToInt32(db.InsertWithIdentity(dt)); var obj = db.GetTable<DataTypeTest2>().Where(_ => _.ID == id).First(); #if !SQLCE Assert.AreEqual(innerxml, obj.XmlDoc_.OuterXml); #endif TypeAccessor.WriteConsole(obj); } }