开发者

Why can't compiler find partial classes extending dbml?

I have a partial class called "trucks" which was automatically generated using LINQ to SQL designer. I extended the class using a partial class of the same name in a separate code file. I added a method called "ContainerCount" to my extender class. During development, the solution will sometimes build fine, but will sometimes come up with an error saying...

CS1061: 'truck' does not contain a definition for 'ContainerCount' and no extension method 'ContainerCount' accepting a first argument of type 'truck' could be found (are you missing a using directive or开发者_开发问答 an assembly reference?)

During development, all I had to do is build it again, and it would be without errors. It seems to be hit or miss. But now that I've uploaded it to the server, it shows the same error consistently.

Any ideas on why the compiler sometimes sees the rest of the partial class and sometimes doesn't?

//from DBML file
[Table(Name="dbo.truck")]
public partial class truck : INotifyPropertyChanging, INotifyPropertyChanged
{...}

//from extension file
public partial class truck
{
    public int ContainerCount(CTSDataClassesDataContext db)
    {...}
}

//Code that creates error
int tContainers = 0;
foreach (var t in trucks)
{
    tContainers += t.ContainerCount(db);
}


It looks like when I do a build via "Build->Build Solution" after editing the dbml file, it tries to keep using an outdated dll. When I use "Build->Rebuild Solution" then it works fine. Looks like a bug keeps Visual Studio from seeing that the edited dbml needs to be rebuilt.

Hope this helps someone with the same problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜