2

Im recently struggling with problem related to Linq data exposition. My task is to extract information out of 3 tables. One, which contains list of the resources and the other one with information about related services. These two tables are joined with the junction table. Structure:

Resource Table:
ResourceID (PK)
Description

ServiceResources Table (junction table):
ServiceID(FK)
Resource(FK)

Service Table:
ServiceID (PK)
Description

Version above is simplified, tables are more extended.

So the question is: I generated special object which will contain all the useful information:

public class ResourceAndService
    {

        public string Resource
        {
            get;
            set;
        }
        public string Service
        {
            get;
            set;
        }(...)

And I want to fill it with informations from the linq query, which should return IList:

    public IList<ResourceAndService> ReturnListOfServicesAndResources()
    {
        var dt = (from res in entities.Resource 
                  from service in entities.Service 
                 select
               new ResourceAndService(){
                        Resource = res.ResourceID,
                        Service= ser.ServiceID,
           (...)
               }).ToList();

        return dt;
    }

Unfortunately continuously, when I try to execute this command, there are warnings in the debug window saying:

A first chance exception of type 'System.NullReferenceException' occurred in RaportBrowser.DLL

And query never finishes.

Do you have any experience with such a problem?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
michaelpan
  • 21
  • 1

1 Answers1

0

OK, the problem with null pointer exception was somewhere else.
By the way, for your info the right way to access junction table is:

public IList<ResourceAndService> ReturnListOfServicesAndResources()
{
    var dt = (from res in entities.Resource 
                from service in res.Service 
                select
                new ResourceAndService()
                {
                    Resource = res.ResourceID,
                    Service= ser.ServiceID,
                    (...)
                }).ToList();
    return dt;
}
eeerahul
  • 1,629
  • 4
  • 27
  • 38
michaelpan
  • 21
  • 1