Associate attribute with code generated property in .net

I wish to set an attribute on a public property in .NET, however I do not have access to the explicit property itself, as this has been code generated in another file.

I have this field:

public virtual string Name { get; set; }

I wish to set this:

[ValidateNonEmpty("Name is required", ExecutionOrder = 1)]
public virtual string Name { get; set; }

My class is marked as partial, but you cannot have partial properties. I thought I was on to something with the MetadataType class which is a new feature of Dynamic Data and DataAnnotations, but alas I feel it can only be used with Dynamic Data, is this true?


Is there any way I can set this attributes (even through web.config!) without touching the code generated class?

Thanks in advance,

Linear Programming with Complication

I’m trying to solve a problem that looks like a standard Linear Programming problem with one twist.

We have as input a set of “phrases” each of which has a weight. We need to choose how many times to repeat each phrase in a text to maximize the total weight, subject to a max character length limitation.

This seems like a straightforward linear programming problem, except for the fact that one phrase could be subphrase of another. So for example if your input phrases include “foo bar” and “foo”, then if you repeat the phrase “foo bar”, you also repeat the phrase “foo”. I don’t know how to deal with this in a linear programming model.