I have written the linq query like:
NorthwindContext context = SqlCE;
var query = context.Destinations.Where(i => i.Id >= 1).Select(i => new {
id = i.Id,
name = i.Destination
}).ToArray();
public NorthwindDataContext SqlCE
{
get
{
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
string connectionString = @"Data Source=|DataDirectory|\Database1.mdf";
return new NorthwindDataContext(connectionString);
}
}
I have connected to sqlserver northwind.mdf file. I have values in the table also still i am getting null reference exception. How can i rectify this. How to get values in to the query.
Regards
NorthwindContext context = null;
if the context is null, then yourvar query
line is like sayingnull.Destinations...
so that's where your null reference exception is coming from. – cfeduke Jan 9 '13 at 17:23