zoukankan      html  css  js  c++  java
  • EFCore 状态跟踪

     //
        // 摘要:
        //     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
        }

    生命周期

    var adduser =new UserInfo(){

       UserName="test1",

       UserAge=18,

       Description=".net"

    }

    using (EFCoreDbContext context=new EFCoreDbContext())
                        {
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Detached
                            context.UserInfo.Add(addurl);
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Added
                            context.SaveChanges();
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Unchanged
                            addurl.UserName = "添加2";
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Modified
                            context.SaveChanges();
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Unchanged
                            context.UserInfo.Remove(addurl);
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Deleted
                            context.SaveChanges();
                            Console.WriteLine(context.Entry<UserInfo>(adduser).State);//Detached
                           
                        }
  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/qingjiawen/p/15112318.html
Copyright © 2011-2022 走看看