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

  • Home
  • SEARCH
  • 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 1068505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:17:47+00:00 2026-05-16T20:17:47+00:00

I’m working on a distributed app with a server and a client, where the

  • 0

I’m working on a distributed app with a server and a client, where the server exposes services via WCF. The server uses the Entity Framework, and its various methods return EntityObjects.

In the client, I have no references to the server. So in the client, the classes are wholly generated proxies.

I have a delete method in the server. When I pass an object (back) to it for deletion, it does this (stripped of exception handling etc):

public void DeleteCarrier(CarrierDefinition carrier)
{
    var container = new WsaEntities();

    if (carrier.EntityState == EntityState.Detached)
    {
        container.CarrierDefinitions.Attach(carrier);
    }
    container.CarrierDefinitions.DeleteObject(carrier);

    container.SaveChanges();
}

Two other tables have foreign keys to CarrierDefinition. One of the FKs is nullable with an ON CASCADE SET NULL constraint, the other has CASCADE DELETE. The above code throws me an exception:

The operation failed: The relationship
could not be changed because one or
more of the foreign-key properties is
non-nullable. When a change is made to
a relationship, the related
foreign-key property is set to a null
value. If the foreign-key does not
support null values, a new
relationship must be defined, the
foreign-key property must be assigned
another non-null value, or the
unrelated object must be deleted.

However, if I delete an entity which hasn’t been round-tripped in this way, it works as expected:

public void DeleteCarrier(Guid carrierId)
{
    var container = new WsaEntities();

    var c = container.CarrierDefinitions.Where(cd => cd.Id == carrierId).First();
    container.CarrierDefinitions.DeleteObject(c);

    container.SaveChanges();
}

Here, the ON CASCADE SET NULL and ON CASCADE DELETE works just fine.

I have inspected the carrier (entity) argument in debug mode, and haven’t been able to find anything amiss. Specifically, the entity collections are populated, and contain the related objects. It looks amazingly complete and correct, considering that it has been serialized, then deserialized to a proxy class and vice versa. But somewhere, something just isn’t quite right.

I know I can just as well use this method signature and move on, or even keep the signature and use the carrier argument’s Id property in place of the carrierId argument. But I’m worried that this will be the first of many problems because something is unsound with the whole approach.

What can I try? Is there anything I should do besides attaching the entity, for example?

I should mention that I’m using the SQL Server Compact Edition v3.5 here, although it doesn’t seem to me like that’s the problem in this particular case.

  • 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-16T20:17:48+00:00Added an answer on May 16, 2026 at 8:17 pm

    For any of you who might be here with the same kind of trouble: I solved this problem by moving to self-tracking entities. These are made for round-tripping, and are much easier to work with upon return. Check it out.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.