Can Editor be told to ignore a field in a .NET model
Can Editor be told to ignore a field in a .NET model
I'm using Editor in a .NET MVC 5 Code first application. On of my Entity models sets up a foreign key relationship with
public class user {
public int Id {get ; set; }
public string first_name { get; set; }
// Setting foreign key for code first model
public virtual Site site { get; set; }
public int site_Id { get; set; }
}
If I use my model for Editor it tries to select 'site' from the user table - can I add a DataAnnotation or similar to get Editor to ignore this field?
To work around this I've setup DTO's in a separate directory but they're almost identical to my Models as I can't change the naming convention at all.
And is there anyway to use a class in a JoinModel class without declaring it in there?
So instead of user / site example provided in the docco - do something like
public class JoinModel {
public user user { get; set; }
public site site { get; set; }
}
and have it pick up the values of the classes instead of trying to select 'user'
This question has an accepted answers - jump to answer
Answers
Update to this - I've edited the DataTables.dll Editor and Attribute class to do what I need. To Attribute I've added this:
And I've added the following to Editor._FieldFromModel
Now my DTO for a Join table is declared like this:
and in My Models I can add
above the virtual class names to ignore those
Hopefully these changes haven't fundamentally broken something else...
Thanks for posting this. Currently no, there is no option to have Editor ignore a parameter in a model. I like your solution though and will consider that for a future release.
I don't believe what you have done above would break anything.
Regards,
Allan
One last change, I had to add a similar thing in the MJoin where it builds the fields from the model