Help extending a partial class generated by EF

Hey,

So let's say EF auto generates a class to model the database in this file:

namespace test.data { using System; ... public partial class Car { public int id { get; set; } public string model { get; set; } } } 

I'm trying to define a new method that acts on the Car() object, in another file in the same assembly:

namespace test.data { using System; ... public partial class Car { public string TestMethod() { return this.id.ToString(); } } } 

Or just something stupid like that. Now, let's say I try and use this stuff in another file in another assembly:

... using test.data; ... var x = myCar.TestMethod(); 

(assume myCar is initialized and all that properly).

So, for some reason, I keep getting the error:

test.data.Car does not contain a definition for 'GetColor' and no extension method 'test' accepting a first argument of type 'test.data.Car' could be found (are you missing a using directive or an assembly reference?) 

So the weird thing about this is that Intellisense/auto-completion is picking up on the TestMethod and completing it for me on Car objects. Also, when I hover over 'var x' it shows "Class System.String" so it recognizes what the method is and what it should do. It seems like I have everything in the correct namespace and included properly, and I can build the test.data assembly with the two definition files just fine. All the auto-generated stuff also works fine. Why is this error coming up when I build the solution?

Thanks!

by casey12141 via /r/csharp

Leave a Reply