I have the following compiled query added to my ASP.NET MVC 2 project (as a partial class definition to my LINQ to SQL DataContext):
namespace MyWebApp.DataAccessLayer.DataObject
{
public partial class MyWebAppDataContext
{
public static Func<MyWebAppDataContext, int, IQueryable<PurchaseOrder>>
POByID = CompiledQuery.Compile
((MyWebAppDataContextcontext, int poID) =>
context.PurchaseOrders.Where(p => p.ID == poID));
public IQueryable<PurchaseOrder> GetPObyID(int categoryID)
{
return POByID(this, categoryID);
}
}
}
To get PurchaseOrder list I use this code in the controller:
using MyWebApp.DataAccessLayer.DataObject;
...
...
var context = new MyWebAppDataContext("...connectionstring...");
var MyPOs = context.GetPObyID(3).ToList();
The IntelliSense does see GetPObyID() function and VS does not see any error in the code but I got the following compilation error:
“error CS1061: ‘MyWebApp.DataAccessLayer.DataObject.MyWebAppDataContext’ does not contain a definition for ‘GetPObyID’ and no extension method ‘GetPObyID’ accepting a first argument of type ‘MyWebApp.DataAccessLayer.DataObject.MyWebAppDataContext’ could be found (are you missing a using directive or an assembly reference?)”
Any suggestions?
Thanks
I could not reproduce your problem in VS2008.
Which tool did you use to compile your project? I guess that the cs file which includes the first section code in your question was missed during the compiling.