Hi nauna,
You can create a method that will return Anonymous types as an object.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
C#
protected void Page_Load(object sender, EventArgs e)
{
var employee = GetEmployees();
}
private object GetEmployees()
{
NorthwindEntities entities = new NorthwindEntities();
var q = from emp in entities.Employees
select emp;
return q;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim employee = GetEmployees()
End Sub
Private Function GetEmployees() As Object
Dim entities As NorthwindEntities = New NorthwindEntities()
Dim q = From emp In entities.Employees Select emp
Return q
End Function