Linq query with a join - how do I return it from a function

C

chris.kennedy

I have a linq query that I want to return from a function. What would
be the type I return and how do I grab the data from the function.


Dim col = (From TBLContactData In ctx.TBLContactData _
Join TBLCompanyContacts In ctx.TBLCompanyContacts On
TBLCompanyContacts.CompanyContactID Equals
TBLContactData.TBLCompanyContacts.CompanyContactID _
Order By TBLContactData.ContactDataID _
Select ContactDataID = TBLContactData.ContactDataID)
 
M

mesut

I've had the same problem but didn't work through. I think first you
need to define a class and your class should contain the fields that
your pojection (=select statement) contains.
the class and fields/columns should have declarative declaration in
the class like below

so your selectstatement should be identical to the fields in your
class (see below)...

from there you can cast

var Col = from ...
select new Customer { ... };

e.g.
[DataObject(true)]
public class Customer
{

public Customer(){}

public string ID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZIPCode { get; set; }
public string Phone { get; set; }
}
 
F

Frans Bouma [C# MVP]

I have a linq query that I want to return from a function. What would
be the type I return and how do I grab the data from the function.


Dim col = (From TBLContactData In ctx.TBLContactData _
Join TBLCompanyContacts In ctx.TBLCompanyContacts On
TBLCompanyContacts.CompanyContactID Equals
TBLContactData.TBLCompanyContacts.CompanyContactID _
Order By TBLContactData.ContactDataID _
Select ContactDataID = TBLContactData.ContactDataID)

In the IDE, hover over 'col', it should show you the type.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top