How to avoid duplicate insert in Entity Framework 4.3.1

后端 未结 1 1242
北海茫月
北海茫月 2021-01-16 15:34

I have a small model created using code-first approach - a class City which contains only information about city name.

public class City
{
    p         


        
相关标签:
1条回答
  • 2021-01-16 16:20

    You need to set the State of your city when you attach it to unchanged

    context.Entry(city).State = EntityState.Unchanged;
    
    0 讨论(0)
提交回复
热议问题