I have two tables with common a field called
imo_no.
I want to join these two tables, but how can I do that?
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
namespace SilverlightBingMapControl.Web
{
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class PositionService
{
[OperationContract]
List<it_position> GetAllPositions()
{
PositionDataClassesDataContext context = new PositionDataClassesDataContext();
var result = from positions in context.it_positions select positions;
return result.ToList();
}
[OperationContract]
List<it_vessel> GetAllVessels()
{
PositionDataClassesDataContext ser = new PositionDataClassesDataContext();
var res = from vessels in ser.it_vessels select vessels;
return res.ToList();
}
}
}
Changes:
I tried this, but got error:
[OperationContract]
List<it_vessel> GetAllInitialize()
{
PositionDataClassesDataContext context = new PositionDataClassesDataContext();
var res = from positions in context.it_positions
join vessels in context.it_vessels on positions.imo_no equals vessels.imo_no
select;
return res.ToList();
}
Error 2 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'. C:\Users\student\KM\SilverlightBingMapControl - 2013-02-11\SilverlightBingMapControl\SilverlightBingMapControl.Web\PositionService.svc.cs 40 23 SilverlightBingMapControl.Web
Error 3 The type arguments for method 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\Users\student\KM\SilverlightBingMapControl - 2013-02-11\SilverlightBingMapControl\SilverlightBingMapControl.Web\PositionService.svc.cs 43 20 SilverlightBingMapControl.Web
Error 4 Invalid expression term ';' C:\Users\student\KM\SilverlightBingMapControl - 2013-02-11\SilverlightBingMapControl\SilverlightBingMapControl.Web\PositionService.svc.cs 41 29 SilverlightBingMapControl.Web
Error 5 ; expected C:\Users\student\KM\SilverlightBingMapControl - 2013-02-11\SilverlightBingMapControl\SilverlightBingMapControl.Web\PositionService.svc.cs 41 30 SilverlightBingMapControl.Web