return type problem
-
I am extracting two fields from two tables , first field is from first table and other is from second table.When i return the query , i am unable to get the fields name like i have a function
private function ret()as object
dim query = from p in datacontext.gettable(of tablename) _
group join a in datacontext.gettable(of tablename1) _
on p.id equals a.id into c = group from c1 in c.DefaultIfEmpty() _
selcet field1 = p.name , field2 = c1.name1
return query
end subprivate sub abc()
dim query = ret()
'When i write the query.
'I does not display the field1 and field2.
'Why it is happening
end sub -
I am extracting two fields from two tables , first field is from first table and other is from second table.When i return the query , i am unable to get the fields name like i have a function
private function ret()as object
dim query = from p in datacontext.gettable(of tablename) _
group join a in datacontext.gettable(of tablename1) _
on p.id equals a.id into c = group from c1 in c.DefaultIfEmpty() _
selcet field1 = p.name , field2 = c1.name1
return query
end subprivate sub abc()
dim query = ret()
'When i write the query.
'I does not display the field1 and field2.
'Why it is happening
end subYou're returning an object. The only methods available on an object are
ToString()
,Equals()
,GetType()
andGetHashCode()
. Try returning a more appropriate type from your function.Deja View - the feeling that you've seen this post before.
-
You're returning an object. The only methods available on an object are
ToString()
,Equals()
,GetType()
andGetHashCode()
. Try returning a more appropriate type from your function.Deja View - the feeling that you've seen this post before.
-
If i am fetching the data from two tables , say , field1 from table1 and field2 from table2 .In this case what should I return ?
LINQ querues return IEnumerable(of T) In your example you're creating an anonymous type[^], so T is an anonymous type, so passing it as a return of a function is going to be an issue. Object will work of course, but how do you get the results? 1) don't use an anonymous type, use a Structure or Class e.g.
Select New MyType With { .field1 = p.name , .field2 = c1.name1 }
2) return an anonymous type and use reflection to get the property values This is what I do for my Report generator - it does not know the type the report will generate, but it gets a list of properties from the report and uses Reflection.'Howard