Is there a way I can have a generated code file like so:
public partial class A {
public string a {get; set;}
}
and then in another file:
public partial class A {
[Attribute("etc")]
public string a {get; set;}
}
So that I can have a class generated from the database and then use a non-generated file to mark it up?
Not as such; the compiler will complain that the member is defined in multiple parts. However, as the use of custom attributes is reflective in nature, you could define a "metadata" class and use it to contain decorators.
You need to define a partial class for your
A
class just like below exampleI've seen something like this done in an article by Scott Guthrie (near the end of it) - didn't try it myself, though.
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
Here is the solution I have been using for such cases. It is useful when you have auto-generated classes that you want to decorate with attributes. Let's say this is the auto-generated class:
And let's say, I would like to add an attribute to specify that UserId is the key. I would then create a partial class in another file like this:
This is my answer
different class files or you can combine the metadatas in a same file but keep the namespace the same..so they can see each other obviously.
keep in mind when you update your model like add more columns you have to update the project class too.