Skip to content

Value of Type Dbset(Of Product) can't be converted to value Object Query(Of Product) #2077

Open
@kgs1951

Description

@kgs1951

Type of issue

Code doesn't work

Description

    Dim dataEntities As AdventureWorksLT2022Entities = New AdventureWorksLT2022Entities

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        **_Dim products As ObjectQuery(Of Product) = dataEntities.Products_**
        Dim query =
            From product In products
            Where product.Color = "Red"
            Order By product.ListPrice
            Select product.Name, product.Color, CategoryName = product.ProductCategory.Name, product.ListPrice

        DataGrid1.ItemsSource = query.ToList()
    End Sub

Page URL

https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/walkthrough-display-data-from-a-sql-server-database-in-a-datagrid-control?view=netframeworkdesktop-4.8

Content source URL

https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/framework/wpf/controls/walkthrough-display-data-from-a-sql-server-database-in-a-datagrid-control.md

Document Version Independent Id

e76201c9-a0c3-5d1f-af69-45c453b4c08f

Platform Id

6125d80b-66e1-7160-f8ec-264b4ce48ff0

Article author

@adegeo

Metadata

Dim dataEntities As AdventureWorksLT2022Entities = New AdventureWorksLT2022Entities

Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    **_Dim products As ObjectQuery(Of Product) = dataEntities.Products_**
    Dim query =
        From product In products
        Where product.Color = "Red"
        Order By product.ListPrice
        Select product.Name, product.Color, CategoryName = product.ProductCategory.Name, product.ListPrice

    DataGrid1.ItemsSource = query.ToList()
End Sub

I get an error message in visual studio that "Value of Type Dbset(Of Product) can't be converted to value Object Query(Of Product)

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions