Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions VB/GridControlCRUD.Common.Northwind/Northwind - VB/Category.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Imports System
Imports System.Collections.Generic
Imports System.Linq

Namespace DevExpress.CRUD.Northwind
Public Class Category
Public Property Id() As Long
Public Property Name() As String
Public Property Description() As String
Public Overridable Property Products() As ICollection(Of Product)
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Imports System
Imports System.Collections.Generic
Imports System.Data.Entity
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks

Namespace DevExpress.CRUD.Northwind
Public Class NorthwindContext
Inherits DbContext

Shared Sub New()
Database.SetInitializer(New NorthwindContextInitializer())
End Sub
Protected Overrides Sub OnModelCreating(ByVal modelBuilder As DbModelBuilder)
modelBuilder.Entity(Of Product)().Property(Function(x) x.Name).IsRequired()
End Sub
Public Property Categories() As DbSet(Of Category)
Public Property Products() As DbSet(Of Product)
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Imports System.Collections.Generic
Imports System.Data.Entity

Namespace DevExpress.CRUD.Northwind
Public Class NorthwindContextInitializer
Inherits DropCreateDatabaseIfModelChanges(Of NorthwindContext)

Protected Overrides Sub Seed(ByVal context As NorthwindContext)
MyBase.Seed(context)

Dim categories = New List(Of Category) _
From {
New Category With {
.Name = "Beverages",
.Description = "Soft drinks, coffees, teas, beers, and ales",
.Products = New List(Of Product) From {
New Product With {
.Name = "Chai",
.QuantityPerUnit = "10 boxes x 20 bags",
.UnitPrice = CDec(18),
.UnitsInStock = 39,
.UnitsOnOrder = 0,
.ReorderLevel = 10,
.Discontinued = False,
.EAN13 = "070684900001"
},
New Product With {
.Name = "Ipoh Coffee",
.QuantityPerUnit = "16 - 500 g tins",
.UnitPrice = CDec(46),
.UnitsInStock = 17,
.UnitsOnOrder = 10,
.ReorderLevel = 25,
.Discontinued = False,
.EAN13 = "070684900043"
}
}
},
New Category With {
.Name = "Condiments",
.Description = "Sweet and savory sauces, relishes, spreads, and seasonings",
.Products = New List(Of Product) From {
New Product With {
.Name = "Aniseed Syrup",
.QuantityPerUnit = "12 - 550 ml bottles",
.UnitPrice = CDec(10),
.UnitsInStock = 13,
.UnitsOnOrder = 70,
.ReorderLevel = 25,
.Discontinued = False,
.EAN13 = "070684900003"
},
New Product With {
.Name = "Louisiana Fiery Hot Pepper Sauce",
.QuantityPerUnit = "32 - 8 oz bottles",
.UnitPrice = CDec(21.05),
.UnitsInStock = 76,
.UnitsOnOrder = 0,
.ReorderLevel = 0,
.Discontinued = False,
.EAN13 = "070684900065"
}
}
},
New Category With {
.Name = "Grains/Cereals",
.Description = "Breads, crackers, pasta, and cereal",
.Products = New List(Of Product) From {
New Product With {
.Name = "Singaporean Hokkien Fried Mee",
.QuantityPerUnit = "32 - 1 kg pkgs.",
.UnitPrice = CDec(14),
.UnitsInStock = 26,
.UnitsOnOrder = 0,
.ReorderLevel = 0,
.Discontinued = True,
.EAN13 = "070684900042"
},
New Product With {
.Name = "Ravioli Angelo",
.QuantityPerUnit = "24 - 250 g pkgs.",
.UnitPrice = CDec(19.5),
.UnitsInStock = 36,
.UnitsOnOrder = 0,
.ReorderLevel = 20,
.Discontinued = False,
.EAN13 = "070684900057"
}
}
}
}

context.Categories.AddRange(categories)
context.SaveChanges()
End Sub
End Class
End Namespace
18 changes: 18 additions & 0 deletions VB/GridControlCRUD.Common.Northwind/Northwind - VB/Product.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Imports System
Imports System.Linq

Namespace DevExpress.CRUD.Northwind
Public Class Product
Public Property Id() As Long
Public Property Name() As String
Public Property CategoryId() As Long
Public Overridable Property Category() As Category
Public Property QuantityPerUnit() As String
Public Property UnitPrice() As Decimal?
Public Property UnitsInStock() As Short?
Public Property UnitsOnOrder() As Short?
Public Property ReorderLevel() As Short?
Public Property Discontinued() As Boolean
Public Property EAN13() As String
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Imports System
Imports System.Linq

Namespace DevExpress.CRUD.Northwind.DataModel
Public Class CategoryInfo
Public Property Name() As String
Public Property Id() As Long
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Imports DevExpress.CRUD.DataModel

Namespace DevExpress.CRUD.Northwind.DataModel
Public Class NorthwindDataStorage
Public Sub New(ByVal categories As IDataProvider(Of CategoryInfo), ByVal products As IDataProvider(Of ProductInfo))
Me.Categories = categories
Me.Products = products
End Sub
Public ReadOnly Property Categories() As IDataProvider(Of CategoryInfo)
Public ReadOnly Property Products() As IDataProvider(Of ProductInfo)
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Imports DevExpress.CRUD.DataModel.EntityFramework
Imports DevExpress.CRUD.DataModel

Namespace DevExpress.CRUD.Northwind.DataModel
Public Module NorthwindDataStorageFactory
Public Function Create(ByVal isInDesignMode As Boolean) As NorthwindDataStorage
If isInDesignMode Then
Return New NorthwindDataStorage(New DesignTimeDataProvider(Of CategoryInfo)(Function(id) New CategoryInfo With {
.Id = id,
.Name = "Category " & id
}), New DesignTimeDataProvider(Of ProductInfo)(Function(id) New ProductInfo With {
.Id = id,
.Name = "Product " & id,
.CategoryId = id
}))
End If
Return New NorthwindDataStorage(New EntityFrameworkDataProvider(Of NorthwindContext, Category, CategoryInfo)(createContext:= Function() New NorthwindContext(), getDbSet:= Function(context) context.Categories, getEnityExpression:= Function(category) New CategoryInfo With {
.Id = category.Id,
.Name = category.Name
}, keyProperty:= NameOf(Category.Id)), New EntityFrameworkDataProvider(Of NorthwindContext, Product, ProductInfo)(createContext:= Function() New NorthwindContext(), getDbSet:= Function(context) context.Products, getEnityExpression:= Function(product) New ProductInfo With {
.Id = product.Id,
.Name = product.Name,
.CategoryId = product.CategoryId
}, getKey:= Function(productInfo) productInfo.Id, getEntityKey:= Function(product) product.Id, setKey:= Sub(productInfo, id) productInfo.Id = CLng(Math.Truncate(id)), applyProperties:= Sub(productInfo, product)
product.Name = productInfo.Name
product.CategoryId = productInfo.CategoryId
End Sub, keyProperty:= NameOf(Category.Id)))
End Function
End Module
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Imports System
Imports System.Linq

Namespace DevExpress.CRUD.Northwind.DataModel
Public Class ProductInfo
Public Property Name() As String
Public Property Id() As Long
Public Property CategoryId() As Long
End Class
End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Imports DevExpress.CRUD.DataModel
Imports DevExpress.Xpf.Data
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Threading.Tasks

Namespace DevExpress.CRUD.ViewModel
Public Module DataProviderAsyncExtensions
<System.Runtime.CompilerServices.Extension> _
Public Async Function ReadAsync(Of T As Class)(ByVal dataProvider As IDataProvider(Of T)) As Task(Of IList(Of T))
#If DEBUG Then
Await Task.Delay(500)
#End If
Return Await Task.Run(Function() dataProvider.Read())
End Function
<System.Runtime.CompilerServices.Extension> _
Public Async Function GetQueryableResultAsync(Of T As Class, TResult)(ByVal dataProvider As IDataProvider(Of T), ByVal getResult As Func(Of IQueryable(Of T), TResult)) As Task(Of TResult)
#If DEBUG Then
Await Task.Delay(500)
#End If
Return Await Task.Run(Function() dataProvider.GetQueryableResult(getResult))
End Function
<System.Runtime.CompilerServices.Extension> _
Public Async Function UpdateAsync(Of T As Class)(ByVal dataProvider As IDataProvider(Of T), ByVal entity As T) As Task
#If DEBUG Then
Await Task.Delay(500)
#End If
Await Task.Run(Sub() dataProvider.Update(entity))
End Function
<System.Runtime.CompilerServices.Extension> _
Public Async Function CreateAsync(Of T As Class)(ByVal dataProvider As IDataProvider(Of T), ByVal entity As T) As Task
#If DEBUG Then
Await Task.Delay(500)
#End If
Await Task.Run(Sub() dataProvider.Create(entity))
End Function
End Module
End Namespace
46 changes: 46 additions & 0 deletions VB/GridControlCRUD.Common/DataModel - VB/DesignTimeDataProvider.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Imports DevExpress.Xpf.Data
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Linq.Expressions

Namespace DevExpress.CRUD.DataModel
Public Class DesignTimeDataProvider(Of T As Class)
Implements IDataProvider(Of T)

Private ReadOnly createEntity As Func(Of Integer, T)
Private ReadOnly count As Integer

Public Sub New(ByVal createEntity As Func(Of Integer, T), Optional ByVal count As Integer = 5)
Me.createEntity = createEntity
Me.count = count
End Sub

Private Function IDataProviderGeneric_Read() As IList(Of T) Implements IDataProvider(Of T).Read
Return Enumerable.Range(0, count).Select(createEntity).ToList()
End Function

Private Function IDataProviderGeneric_GetQueryableResult(Of TResult)(ByVal getResult As Func(Of IQueryable(Of T), TResult)) As TResult Implements IDataProvider(Of T).GetQueryableResult
Dim queryable = DirectCast(Me, IDataProvider(Of T)).Read().AsQueryable()
Return getResult(queryable)
End Function

Private Sub IDataProviderGeneric_Create(ByVal obj As T) Implements IDataProvider(Of T).Create
Throw New NotSupportedException()
End Sub
Private Sub IDataProviderGeneric_Delete(ByVal obj As T) Implements IDataProvider(Of T).Delete
Throw New NotSupportedException()
End Sub
Private Sub IDataProviderGeneric_Update(ByVal obj As T) Implements IDataProvider(Of T).Update
Throw New NotSupportedException()
End Sub

Private ReadOnly Property IDataProviderGeneric_KeyProperty() As String Implements IDataProvider(Of T).KeyProperty
Get
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return throw new NotSupportedException();
Return throw New NotSupportedException()
End Get
End Property
End Class
End Namespace
Loading