Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:13:31+00:00 2026-05-22T20:13:31+00:00

I am trying to do some process against every object in my EntityFramework OnSave.

  • 0

I am trying to do some process against every object in my EntityFramework OnSave. Part of this process involves turning the object into a Binary object. It is taking FOREVER to Serialize and I am about 99% positive that it is because we are using Lazy Loading on our EntityFramework and it is grabbing Lazy Loaded objects that are accessed in PartialClasses.

I tried detaching my object from the ObjectContext, but my coworkers have used Lazy Loading all over our application without first checking if the object was NULL.

For example, there is code like this in our Partial Classes file:
get { return this.ContactsTable.FullName; }
That works fine as long as the object is not Detached. As soon as it is detached I get Null reference errors.

My question is this: Is it possible for me to detach my object and have Lazy Loading not throw Null Reference exceptions, OR is it possible for me to tell the DataContractSerializer to ignore Lazy Loaded objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:13:32+00:00Added an answer on May 22, 2026 at 8:13 pm

    Is it possible for me to detach my
    object and have Lazy Loading not throw
    Null Reference exceptions

    No.

    is it possible for me to tell the
    DataContractSerializer to ignore Lazy
    Loaded objects

    No.

    But there should be simple solution. When you go to serialize the entity call this on the context where the entity is attached:

    // Turn off the lazy loading
    context.ContextOptions.LazyLoadingEnabled = false;
    // Run your serialization here
    ...
    // Turn on the lazy loading again
    context.ContextOptions.LazyLoadingEnabled = true;
    

    But it is whole very strange because serialization will try to serialize all loaded entities and by your description it looks like you never know how big part of the object graph will be serialized.

    If you really want to save only single object detaching is way to go but it will break all relations with other objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to process some JSON into a Java object using some beans and
I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
I'm new to Django, trying to process some forms. I have this form for
I am trying to add some custom build steps to my headless build process
I am trying to process some PHP code to extract keys from a specific
I'm trying to use sed to process some output of a command that is
Some background.... We're venturing into Azure for the first time and are trying to
I am trying some simple code on fork. When I give code like this,
I’m thinking about trying some development for the iPhone, is it possible to install
I'm trying some of the ASP.NET MVC tutorials and one of them has the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.