How to delay loading a property with linq to sql external mapping?

余生颓废 提交于 2020-01-15 03:10:47

问题


I have a table that contains some blob fields that I don't want to load by default.

In a dbml file it is possible to set the delay loaded property for such fields.

Is there a similar option for external mapping files?


回答1:


I'm not familiar with "external mapping files", but this is basically how you do lazy loading with LINQ-to-SQL:

    private System.Data.Linq.Link<String> _content;
    [Column(Name = "content", DbType = "NVarChar(MAX) NOT NULL", Storage = "_content")]
    public String Content
    {
        get { return this._content.Value; }
        set { this._content.Value = value; }
    }

Using System.Data.Linq.Link<String> as the private variable causes that property to be delay loaded, unless delay loading is disabled on the DataContext.




回答2:


I believe you would have to do something like what Daniel Schaffer said in code, but without the [Column] attribute, since you would define the mapping in the XML file.



来源:https://stackoverflow.com/questions/499183/how-to-delay-loading-a-property-with-linq-to-sql-external-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!