0

So I have a few model classes generated by entity framework and I want to customize at least one to fit my project needs. Here is the generated class:

    public partial class Token
    {
        public string token_admin { get; set; }
        public string username { get; set; }
        public string password { get; set; }
    }

And here is how I want to customize it:

    public partial class Token : IdentityUser
    {
        public string token_admin { get; set; }
        public string username { get; set; }
        [JsonIgnore]
        public string password { get; set; }
    }

Obviously each time the models are generated, the IdentityUser and decoration [JsonIgnore] disappear, making it hard to be consistent in my web api returns and impossible to find users using the http filter I setup... (the latter is actually a whole different problem on it's own)

I've been searching but can't find a clear answer to what is required to do here. Any suggestions?

FYI, this is part of a school lab so be lenient on the quality of what I do ;)

JulioQc
  • 310
  • 1
  • 4
  • 20

1 Answers1

0

You should not have to modify the Entity models because you should not return Entity models from your WebApi. Create a separate Token class in your WebApi project and map it with entity framework's model class.

Niraj
  • 376
  • 4
  • 14
  • sounds feasible but how to 'map' exactly? – JulioQc Jun 12 '17 at 19:50
  • I use AutoMapper(http://automapper.org/) to map models between different layers. This will be helpful https://github.com/AutoMapper/AutoMapper/wiki/Getting-started – Niraj Jun 12 '17 at 19:52