本文整理汇总了C#中IContext.CreateObject方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.CreateObject方法的具体用法?C# IContext.CreateObject怎么用?C# IContext.CreateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.CreateObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAuthor
public static Author CreateAuthor(IContext context, string firstName, string lastName)
{
//Ask the context to create a new author object
Author author = (Author) context.CreateObject(typeof(Author));
//Set the properties
author.FirstName = firstName;
author.LastName = lastName;
//Commit the new object to the database
context.Commit();
return author;
}
示例2: CreateProduct
private Product CreateProduct(IContext context, string name, decimal price)
{
Category category = (Category) context.TryGetObjectByNPath("Select * from Category Where CategoryName = 'Fruit'", typeof(Category));
if (category == null)
{
category = (Category) context.CreateObject(typeof(Category));
category.CategoryName = "Fruit";
context.Commit();
}
Product product = (Product) context.CreateObject(typeof(Product));
product.ProductName = name;
product.UnitPrice = price;
product.Category = category;
return product;
}
示例3: CreateOrderDetail
private OrderDetail CreateOrderDetail(IContext context, Order order, Product product, short qty)
{
OrderDetail orderDetail = (OrderDetail) context.CreateObject(typeof(OrderDetail));
orderDetail.Order = order;
orderDetail.Product = product;
orderDetail.Quantity = qty;
orderDetail.UnitPrice = product.UnitPrice;
return orderDetail;
}
示例4: CreateOrder
private Order CreateOrder(IContext context, Customer customer)
{
Order order = (Order) context.CreateObject(typeof(Order));
order.Customer = customer;
return order;
}
示例5: CreateEmployee
private Employee CreateEmployee(IContext context, string FirstName, string lastName)
{
//first we create a new employee
Employee employee = (Employee) context.CreateObject(typeof(Employee));
//we set some values and save
employee.FirstName = FirstName;
employee.LastName = lastName;
context.Commit();
return employee;
}