In L2S (having anonymouse type), I'm able to get the 3 column values below but what is the equivalent in EF?
Dim northwind = From product In dbNorthWind.Products
Join supplier In dbNorthWind.Suppliers On supplier.SupplierID Equals product.SupplierID _
Join category In dbNorthWind.Categories On category.CategoryID Equals product.CategoryID _
Where product.ProductId = 1234 _
Select New With { _
.ProductName = product.ProductName,
.CategoryName = category.CategoryName,
.SupplierName = supplier.CompanyName
}
I tried below code but returns all columns by using EF.
Dim northwind = dbNorthWind.Products.Include("Suppliers").Include("Categories").Where(Function(i) i.ProductId = 1234)
Member
321 Points
1309 Posts
How to get column values using EF?
Jul 27, 2014 10:49 AM|imperialx|LINK
In L2S (having anonymouse type), I'm able to get the 3 column values below but what is the equivalent in EF?
I tried below code but returns all columns by using EF.
-imperialx
All-Star
37441 Points
9078 Posts
Re: How to get column values using EF?
Jul 27, 2014 11:17 AM|AidyF|LINK
The same technique will work, just add
.Select
to return a list of your anonymous types. An example can be found here
http://stackoverflow.com/questions/3142225/whats-the-equivalent-vb-net-syntax-for-anonymous-types-in-a-linq-statement
Member
321 Points
1309 Posts
Re: How to get column values using EF?
Jul 27, 2014 11:43 AM|imperialx|LINK
If I use below there is no field properties (data columns) available. No intellisense for property CategoryName field.
.Select(Function(d) New With {.CategoryName = d.Categories.CategoryName})
Star
12777 Points
1635 Posts
Re: How to get column values using EF?
Jul 29, 2014 03:49 AM|Terry Guo - MSFT|LINK
Hi imperialx,
Please try to change your code as below:
Best Regards,
Terry Guo