//
    // 摘要:
    //     The state in which an entity is being tracked by a context.
    public enum EntityState
    {
        //
        // 摘要:
        //     The entity is not being tracked by the context.
        Detached = 0,
        //
        // 摘要:
        //     The entity is being tracked by the context and exists in the database. Its property
        //     values have not changed from the values in the database.
        Unchanged = 1,
        //
        // 摘要:
        //     The entity is being tracked by the context and exists in the database. It has
        //     been marked for deletion from the database.
        Deleted = 2,
        //
        // 摘要:
        //     The entity is being tracked by the context and exists in the database. Some or
        //     all of its property values have been modified.
        Modified = 3,
        //
        // 摘要:
        //     The entity is being tracked by the context but does not yet exist in the database.
        Added = 4
    }

 

生命周期

using (EFCoreDbContext context=new EFCoreDbContext())
                    {
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Detached
                        context.UserInfo.Add(addurl);
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Added
                        context.SaveChanges();
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Unchanged
                        addurl.UserName = "添加2";
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Modified
                        context.SaveChanges();
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Unchanged
                        context.UserInfo.Remove(addurl);
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Deleted
                        context.SaveChanges();
                        Console.WriteLine(context.Entry<UserInfo>(addurl).State);//Detached
                       
                    }