zoukankan      html  css  js  c++  java
  • SharePoint中使用Linq出现未将对象引用到实例化的解决方法

    今天在使用Sharepoint的Linq是出现为未将对象引用实例化的问题。在网上一下,发现许多朋友也出现相同的问题。

    问题代码

    using (DataContext ctx = new DataContext(portalUrl))
    {
    EntityList<CustomConfiguration> constConfig = ctx.GetList<EC.Entities.ConstantsConfiguration>("Custom Configuration");
    IList<CustomConfiguration> list=constConfig.ToList();
    }

    程序运行到ToList()的时候就会报错:

    Category: SharePoint Guidance: An exception has occurred.   ExceptionType: 'NullReferenceException'   ExceptionMessage: 'Object reference not set to an instance of an object.'   StackTrace: ' 
    at Microsoft.SharePoint.Linq.SPItemMappingInfo.GetId(SPListItem item, String listName)     
    at Microsoft.SharePoint.Linq.SPItemMappingInfo.MaterializeEntity[TEntity](DataContext dc, SPDataList list, SPListItem item, SPItemMappingInfo itemMappingInfo, JoinPath joinPath) …

    检查发现将DataContext.ObjectTrackingEnabled设为False,再使用ToList()程序就可以通过了。

    正确代码

    using (DataContext ctx = new DataContext(portalUrl))
    {
        ctx.ObjectTrackingEnabled = false;
        EntityList<CustomConfiguration> constConfig = ctx.GetList<EC.Entities.ConstantsConfiguration>("Custom Configuration");
        IList<CustomConfiguration> list=constConfig.ToList();
    }
    

      

    SDK中关于ObjectTrackingEnabled属性的描述:

    Default: true

    gets or sets a value that indicates whether changes in objects are tracked. If this property is false ,changes cannot be persisted to the content database .

    If your code only queries lists, rather than adding, deleting, or editing list items, then you can turn off object change tracking. Doing so will improve performance. Set the ObjectTrackingEnabled property to false.


     

  • 相关阅读:
    centos7 安装docker 对应的 rabbitmq3.6.15
    golang中defer的使用规则
    Yii2-redis 不用 composer 的安装
    安装并使用PHPunit
    PHP Taint – 一个用来检测XSS/SQL/Shell注入漏洞的扩展
    SQL Antipatterns——SQL 反模式(二)
    tp5 No input file specified.
    vue 封装自定义组件
    判断微信访问
    phalcon windows下安装phalcon-devtools 官网的坑
  • 原文地址:https://www.cnblogs.com/snailJuan/p/2475511.html
Copyright © 2011-2022 走看看