本文整理汇总了VB.NET中System.Data.Objects.ObjectContext.Connection属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ObjectContext.Connection属性的具体用法?VB.NET ObjectContext.Connection怎么用?VB.NET ObjectContext.Connection使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Data.Objects.ObjectContext
的用法示例。
在下文中一共展示了ObjectContext.Connection属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: EntityConnection
' Define the order ID for the order we want.
Dim orderId As Integer = 43680
' Create an EntityConnection.
Dim conn As New EntityConnection("name=AdventureWorksEntities")
' Create a long-running context with the connection.
Dim context As New AdventureWorksEntities(conn)
Try
' Explicitly open the connection.
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
' Execute a query to return an order.
Dim order As SalesOrderHeader = context.SalesOrderHeaders.Where("it.SalesOrderID = @orderId", _
New ObjectParameter("orderId", orderId)).Execute(MergeOption.AppendOnly).First()
' Change the status of the order.
order.Status = 1
' You do not have to call the Load method to load the details for the order,
' because lazy loading is set to true
' by the constructor of the AdventureWorksEntities object.
' With lazy loading set to true the related objects are loaded when
' you access the navigation property. In this case SalesOrderDetails.
' Delete the first item in the order.
context.DeleteObject(order.SalesOrderDetails.First())
' Save changes.
If 0 < context.SaveChanges() Then
Console.WriteLine("Changes saved.")
End If
' Create a new SalesOrderDetail object.
' You can use the static CreateObjectName method (the Entity Framework
' adds this method to the generated entity types) instead of the new operator:
' SalesOrderDetail.CreateSalesOrderDetail(1, 0, 2, 750, 1, (decimal)2171.2942, 0, 0,
' Guid.NewGuid(), DateTime.Today));
Dim detail = New SalesOrderDetail With
{
.SalesOrderID = 0,
.SalesOrderDetailID = 0,
.OrderQty = 2,
.ProductID = 750,
.SpecialOfferID = 1,
.UnitPrice = CDec(2171.2942),
.UnitPriceDiscount = 0,
.LineTotal = 0,
.rowguid = Guid.NewGuid(),
.ModifiedDate = DateTime.Now
}
order.SalesOrderDetails.Add(detail)
' Save changes again.
If 0 < context.SaveChanges() Then
Console.WriteLine("Changes saved.")
End If
Catch ex As InvalidOperationException
Console.WriteLine(ex.ToString())
Finally
' Explicitly dispose of the context and the connection.
context.Dispose()
conn.Dispose()