0
votes

Ok, so I have this in one of my model files -

public string FullName { get { return FirstName + " " + LastName; } }

This has been entered by me and not automatically by EF.

When I run update from database within the .edmx file, the above code gets deleted.

I have tried putting it into a meta data / partial class, but it seems that is only working for data annotations.

Is there a way of keeping the custom FullName field when updating the model from database?

I know I could use view models, but would rather not

1
I know I could use view models, but would rather not? Seriously. Always use a view model.user3559349
@StephenMuecke so would you advise to do all the data annotation and custom fields in a view model rather than partial classes etc?SK2017
Absolutely (is a pity its not mandatory)user3559349
@StephenMuecke is right. Using viewmodels should always be done. Think of the need of getting properties of two of your models with one database request. And you can also get rid of transferring meta information of your database tables, which you often simply don't need!schlonzo

1 Answers

0
votes

try [NotMapped] attribute

ie

[NotMapped]
public string FullName { get { return FirstName + " " + LastName; } }