LINQ sentence error

G

Guest

Hi

I have VS .NET 2005 and I install LinQ preview for C#.
I'm try to make some thing using LINQ.

IT returns error in this sentence :

var query = from p in people.People
from s in people.Salaries
where p.ID == s.ID)
select new { p.LastName, p.FirstName, s.Year,
s.SalaryYear};

And don't recognize this Sintax.

I will be grateful for your help
 
D

David R. Longnecker

First off, be sure you have added the right references to your project. You'll
need a using statement for System.Linq.

Looking at your LINQ code, It may be just your extra ) in there. Do you
have your foreign key relationships defined (the p.ID = s.ID) in the designer?
If so, the additional "join" shouldn't be necessary.

var query =
from p in people.People
select new { p.LastName, p.FirstName, p.Salaries.Year, p.Salaries.SalaryYear
};

If not, then your query looks good, but it'd be based on the data layout
you have designed.

var query =
from p in people.People
from s in people.Salaries
where p.ID == s.ID
select new { p.LastName, p.FirstName, s.Year, s.SalaryYear };

If it still isn't working, could you maybe post up what the actual compiler
error is?

HTH.

-dl
 

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