本文整理匯總了VB.NET中System.Data.EntityKey類的典型用法代碼示例。如果您正苦於以下問題:VB.NET EntityKey類的具體用法?VB.NET EntityKey怎麽用?VB.NET EntityKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了EntityKey類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: AdventureWorksEntities
Using context As New AdventureWorksEntities()
Dim entity As Object = Nothing
Dim entityKeyValues As IEnumerable(Of KeyValuePair(Of String, Object)) = _
New KeyValuePair(Of String, Object)() {New KeyValuePair(Of String, Object)("SalesOrderID", 43680)}
' Create the key for a specific SalesOrderHeader object.
Dim key As New EntityKey("AdventureWorksEntities.SalesOrderHeaders", entityKeyValues)
' Get the object from the context or the persisted store by its key.
If context.TryGetObjectByKey(key, entity) Then
Console.WriteLine("The requested " & entity.GetType().FullName & " object was found")
Else
Console.WriteLine("An object with this key could not be found.")
End If
End Using
示例2: AdventureWorksEntities
Using context As New AdventureWorksEntities()
Try
' Create the key that represents the order.
Dim orderKey As New EntityKey("AdventureWorksEntities.SalesOrderHeaders", "SalesOrderID", orderId)
' Create the stand-in SalesOrderHeader object
' based on the specified SalesOrderID.
Dim order As New SalesOrderHeader()
order.EntityKey = orderKey
' Assign the ID to the SalesOrderID property to matche the key.
order.SalesOrderID = CInt(orderKey.EntityKeyValues(0).Value)
' Attach the stand-in SalesOrderHeader object.
context.SalesOrderHeaders.Attach(order)
' 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)
context.SaveChanges()
Catch generatedExceptionName As InvalidOperationException
Console.WriteLine("Ensure that the key value matches the value of the object's ID property.")
Catch generatedExceptionName As UpdateException
Console.WriteLine("An error has occurred. Ensure that an object with the '{0}' key value exists.", orderId)
End Try
End Using