本文整理汇总了C#中IRepository.SaveGraph方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.SaveGraph方法的具体用法?C# IRepository.SaveGraph怎么用?C# IRepository.SaveGraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRepository
的用法示例。
在下文中一共展示了IRepository.SaveGraph方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Common_CanUpdate
public void Common_CanUpdate(IRepository<Product> db)
{
// Arrange
var px = new Product
{
ProductName = "Bumble Bee",
Category = "Autobots",
MinimumPrice = 8
};
px.PriceList =
new List<ProductPrice>()
{
new ProductPrice { Product = px, Price = 234, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 300, EffectiveDate = DateTime.Today.AddDays(100) }
};
db.SaveGraph(px);
// int n = px.PriceList[0].ProductPriceId;
// simulate web(i.e. stateless)
int productPriceId = db.Get(px.ProductId).PriceList[0].ProductPriceId;
var fromWeb =
new Product
{
ProductId = px.ProductId,
ProductName = "hahaha", // px.ProductName + "---" + Guid.NewGuid().ToString(),
Category = px.Category,
MinimumPrice = px.MinimumPrice,
RowVersion = db.Get(px.ProductId).RowVersion,
PriceList = new List<ProductPrice>()
};
fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, ProductPriceId = productPriceId, Price = 767676, EffectiveDate = DateTime.Today });
fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, Price = 2148, EffectiveDate = DateTime.Today });
fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, Price = 2048, EffectiveDate = DateTime.Today });
fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, Price = 222, EffectiveDate = DateTime.Today });
/*fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, Price = 888, EffectiveDate = DateTime.Today });
fromWeb.PriceList.Add(new ProductPrice { Product = fromWeb, Price = 222, EffectiveDate = DateTime.Today });*/
// Act
string expecting = "Bumble Bee Battle Mode hickhickhick";
fromWeb.ProductName = expecting;
db.SaveGraph(fromWeb);
// Assert
Assert.AreEqual(expecting, db.Get(fromWeb.ProductId).ProductName);
// Assert.AreNotEqual(px.ProductName, db.Get(fromWeb.ProductId).ProductName);
}
示例2: Refactored_Common_SaveGraph_Arrange_Create
Question Refactored_Common_SaveGraph_Arrange_Create(IRepository<Question> repo)
{
var importantQuestion = PopulateQuestion();
repo.SaveGraph(importantQuestion);
return importantQuestion;
}
示例3: Common_CanSaveHeaderDetail_ThenHeaderOnly
void Common_CanSaveHeaderDetail_ThenHeaderOnly(IRepository<Product> db)
{
// NHibernate.ISession xxx = NhModelsMapper.GetSession(connectionString);
// Arrange
var px = new Product
{
ProductName = "Optimus",
Category = "Autobots",
MinimumPrice = 7
};
px.PriceList =
new List<ProductPrice>()
{
new ProductPrice { Product = px, Price = 777, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 888, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 999, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 222, EffectiveDate = DateTime.Today },
};
// Act
db.SaveGraph(px);
// xxx.Merge(px);
byte[] rv = px.RowVersion;
Assert.AreEqual(4, px.PriceList.Count());
px = db.GetEager(px.ProductId);
Assert.AreEqual("Optimus", px.ProductName);
px.ProductName = px.ProductName + "?";
px.PriceList[2].Price = 333;
Assert.AreEqual(4, px.PriceList.Count);
db.SaveGraph(px);
Assert.AreNotEqual(0, px.ProductId);
CollectionAssert.AreNotEqual(px.RowVersion, rv);
// Assert
Assert.AreEqual(px.ProductName, px.ProductName);
Assert.AreNotEqual(0, px.ProductId);
Assert.AreEqual(4, px.PriceList.Count);
// Arrange
Assert.AreNotEqual(0, px.ProductId);
/* triggers concurrency exception
byte[] x = px.RowVersion;
x[0] += 1;
px.RowVersion = x;
*/
var py = new Product
{
ProductId = px.ProductId,
ProductName = "Optimus",
Category = "Autobotszx",
MinimumPrice = 7,
RowVersion = px.RowVersion
// empty list is incompatible with cascade=all-delete-orphan
};
int pxid = px.ProductId;
db.Save(py);
Product pz = db.Get(px.ProductId);
// throw new Exception(py.ProductId + " " + px.ProductId + " " + pxid);
Assert.AreEqual(px.ProductId, py.ProductId);
Assert.IsNotNull(pz.PriceList);
Assert.AreEqual(4, pz.PriceList.Count);
}
示例4: Common_Orm_SaveGraph_Can_Update
void Common_Orm_SaveGraph_Can_Update(IRepository<Question> repo)
{
// Arrange
Question importantQuestion = Refactored_Common_SaveGraph_Arrange_Create(repo);
string expectedText = "number 9, number 9, number 9...";
// Act
int questionId = importantQuestion.QuestionId;
byte[] rowVersion = importantQuestion.RowVersion;
Question retrievedQuestion = repo.GetEager(questionId);
int originalAnswersCount = retrievedQuestion.Answers.Count;
// throw new Exception(retrievedQuestion.GetType().ToString());
retrievedQuestion.Text = "Hello";
retrievedQuestion.Answers.Single(x => x.Poster == "John").Text = expectedText;
var z = retrievedQuestion.Answers.Single(x => x.Poster == "John");
z.Text = expectedText;
var a = retrievedQuestion.Answers.Single(x => x.Poster == "Paul");
retrievedQuestion.Answers.Remove(a);
repo.SaveGraph(retrievedQuestion); // save the whole object graph
Question retrievedMergedQuestion = repo.GetEager(questionId);
// Assert
Assert.AreNotSame(importantQuestion, retrievedQuestion);
Assert.AreNotSame(retrievedQuestion, retrievedMergedQuestion);
Assert.AreEqual(expectedText, retrievedMergedQuestion.Answers.Single(x => x.Poster == "John").Text);
Assert.AreEqual("Hello", retrievedMergedQuestion.Text);
Assert.AreEqual(3, originalAnswersCount);
Assert.AreEqual(2, retrievedMergedQuestion.Answers.Count);
}
示例5: Common_CanSaveHeaderDetail
void Common_CanSaveHeaderDetail(IRepository<Product> db)
{
// Arrange
var px = new Product
{
ProductName = "Optimus",
Category = "Autobots",
MinimumPrice = 7
};
px.PriceList =
new List<ProductPrice>()
{
new ProductPrice { Product = px, Price = 777, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 888, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 999, EffectiveDate = DateTime.Today },
new ProductPrice { Product = px, Price = 222, EffectiveDate = DateTime.Today },
};
// Act
db.SaveGraph(px);
Assert.AreEqual(4, px.PriceList.Count());
px = db.GetEager(px.ProductId);
Assert.AreEqual("Optimus", px.ProductName);
px.ProductName = px.ProductName + "!";
px.PriceList[2].Price = 333;
Assert.AreEqual(4, px.PriceList.Count);
db.SaveGraph(px);
// Assert
Assert.AreEqual(px.ProductName, px.ProductName);
Assert.AreEqual(px.ProductId, px.ProductId);
Assert.AreEqual(4, px.PriceList.Count);
}