tags:

views:

49

answers:

2

I am trying to get a simple join query from 2 tables , they have no relationship , so far i got this code but there is an error that i dont get it , please help

var query =
                    from p in db.Productos
                    from s in db.Stocks
                    where p.Nombre == "Suaje" && p.TipoProducto == tipo
                    where p.RecID == s.IDProducto
                    select new { s.Largo, s.Ancho };
A: 

Are you missing the 'and'?

  and p.RecID == s.IDProducto

Consider writing your query like this:

var results = from p in db.Productos
join s in db.Stocks
on p.RecID equals s.IDProducto
where p.Nombre == "Suaje" && p.TipoProducto == tipo
select new { s.Largo, s.Ancho };
p.campbell
thx, I am reciving the same error"Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable"
VictorC
+1  A: 

Your query is well formed. I believe the error comes from how you're using the query object.

Are you returning it? What is the return type of the method?

Good practice dictates that you do not return anonymous types (or generic types with anonymous type parameters) from any method.

If all else fails, remove the var keyword and work from there.

David B