I'm just starting out with Entity Framework and I'm concerned about the ease with which a primary key can be overridden. I know I can protect this model in my controller (I'm using WebAPI with ASP.NET MVC 5), but I am wondering if it is possible to prevent anyone setting the ID of my model from the model itself via annotations or something?
Basically can I do this:
public int ID { get; private set; }
or something similar, in an EF6 model?
If this is easily found through Google then I don't know the terms to search. I've not been able to find anything that really answers this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…