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 9315275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:19:17+00:00 2026-06-19T02:19:17+00:00

As I’m working on an ASP.NET MVC project I’ve saw a weird behavior of

  • 0

As I’m working on an ASP.NET MVC project I’ve saw a weird behavior of EF which delays me (to be exact, I’m still stuck on this problem at least month… and only now I’ve realized that my DDD architecture code is not broken and it’s specific an EF-related code bug that I have).

My site has posts. Each post has a set of attributes (PostAttributeValue) and each attribute value has a related PostAttributeDefinition which contains data about it – such as Title, Validation Rules, Raw Value (binary serialized), data type etc.

This is my Post model:

public class Post
{
    #region Settings

    /// <summary>
    /// Maximum linked images
    /// </summary>
    public static int MaximumLinkedImages
    {
        get { return Properties.Settings.Default.MaximumPostsLinkedImages; }
    }

    /// <summary>
    /// Maximum linked image size in MB
    /// </summary>
    public static int MaximumLinkedImageSize
    {
        get { return Properties.Settings.Default.MaximumPostLinkedImageSize; }
    }

    /// <summary>
    /// Delay hours between posts bumping
    /// </summary>
    public static int BumpPostDelayHours
    {
        get { return Properties.Settings.Default.BumpPostDelayHours; }
    }

    #endregion

    #region ctor

    public Post()
    {
        this.Attributes = new List<PostAttributeValue>();
        this.LinkedImages = new List<string>();
    }

    #endregion

    /// <summary>
    /// The parent category that this post was posted into
    /// </summary>
    [Required]
    public virtual Category ParentCategory { get; set; }

    /// <summary>
    /// The post unique identifier
    /// </summary>
    [Key]
    public Guid PostIdentifier { get; set; }

    /// <summary>
    /// The post title (e.g. "Great vila!")
    /// </summary>
    [Required]
    public string Title { get; set; }

    /// <summary>
    /// The post title url alias (e.g. "great-vila")
    /// </summary>
    public string TitleUrlAlias { get; set; }

    /// <summary>
    /// Post extra notes and information written by the author
    /// </summary>
    [Required]
    public string Description { get; set; }

    /// <summary>
    /// The post item city
    /// </summary>
    [Required]
    public virtual City City { get; set; }

    /// <summary>
    /// The post item location
    /// </summary>
    public string Location { get; set; }

    /// <summary>
    /// Is the post was published and marketed by brokerage (Tivuuch)
    /// </summary>
    [Required]
    public bool Brokerage { get; set; }

    /// <summary>
    /// Post custom attributes
    /// </summary>
    public virtual ICollection<PostAttributeValue> Attributes { get; set; }

    /// <summary>
    /// The post assigned price
    /// </summary>
    [Required]
    public int RequestedPrice { get; set; }

    /// <summary>
    /// List of images linked with the post (includes only the name of the picture, a.k.a "foo.png", "bar.jpg" etc.)
    /// </summary>
    public virtual ICollection<string> LinkedImages { get; set; }

    public string LinkedImagesSerialized
    {
        get
        {
            if (this.LinkedImages == null)
            {
                this.LinkedImages = new List<string>();
            }

            return string.Join(",", this.LinkedImages);
        }
        set
        {
            if (this.LinkedImages == null)
            {
                this.LinkedImages = new List<string>();
            }

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            this.LinkedImages = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }

    /// <summary>
    /// Cached generated cached url using IShorterUrlService
    /// </summary>
    public string GeneratedShorterUrl { get; set; }

    /// <summary>
    /// Is this post marked as hot
    /// </summary>
    public bool IsHotPost { get; set; }

    /// <summary>
    /// The post publish status
    /// </summary>
    public PostPublishStatus PublishStatus { get; set; }

    /// <summary>
    /// The post author
    /// </summary>
    public virtual Account Author { get; set; }

    /// <summary>
    /// The author IP address (collected to determine different IPs)
    /// </summary>
    public string AuthorIPAddress { get; set; }

    /// <summary>
    /// The creation date of the post
    /// </summary>
    public DateTime CreationDate { get; set; }

    /// <summary>
    /// The last post modification date
    /// </summary>
    public DateTime LastUpdatedDate { get; set; }

    /// <summary>
    /// The date that the post was bumped at, used to sort the posts in category.
    /// </summary>
    public DateTime LastBumpDate { get; set; }
}

This is PostAttributeValue
public class PostAttributeValue
{
///
/// The attribute value id
///
[Key]
public int AttributeValueId { get; set; }

    /// <summary>
    /// The value owner post
    /// </summary>
    public virtual Post OwnerPost { get; set; }

    /// <summary>
    /// The value attribute definition id
    /// </summary>
    //public int RelatedAttributeDefinitionId { get; set; }

    /// <summary>
    /// The value attribute definition
    /// </summary>
    public virtual PostAttributeDefinition Definition { get; set; }

    /// <summary>
    /// The stored raw value
    /// </summary>
    public byte[] RawValue { get; set; }
}

and this is PostAttributeDefinition
public class PostAttributeDefinition
{
///
/// The filter name
///
[Key]
public int DefinitionId { get; set; }

    /// <summary>
    /// The owner category
    /// </summary>
    [Required]
    public virtual Category OwnerCategory { get; set; }

    /// <summary>
    /// The filter title
    /// </summary>
    [Required]
    public string Title { get; set; }

    /// <summary>
    /// Metadata enum that provides extra data about the data type
    /// </summary>
    public PostAttributeTypeMetadata TypeMetadata { get; set; }

    /// <summary>
    /// Bitwise metadata that provides data about the object in display mode
    /// </summary>
    public PostAttributeDisplayModeMetadata DisplayModeMetadata { get; set; }

    public PostAttributeEditorType EditorType { get; set; }

    /// <summary>
    /// The attribute raw default value
    /// </summary>
    [Required]
    public byte[] RawDataValue { get; set; }

    /// <summary>
    /// The attribute raw associated validation attributes
    /// </summary>
    public byte[] RawValidationRules { get; set; }

    /// <summary>
    /// Is this field required
    /// </summary>
   public bool IsRequired { get; set; }
}

My problem is that when I’m trying to add a new post I’m getting a relationship error (A relationship from the AssociationSet is in the 'Deleted' state)
which is

A relationship from the 'PostAttributeValue_Definition' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'PostAttributeValue_Definition_Source' must also in the 'Deleted' state.

Now, I’ve saw that the problem is that when I’m assigning to PostAttributeValue a definition, automaticlly it becomes Deleted – even if I’m assigning a definition that I’m fetching from the DB right now.

I’ve tested the above code:

        var db = ServiceLocator.SharedInstance.GetInstance<MyDbContext>();
        List<PostAttributeValue> v = new List<PostAttributeValue>();

        var entity =  db.PostAttributesDefinitions.Where(d => d.DefinitionId==1).Include(d => d.OwnerCategory).First();
        v.Add(new PostAttributeValue() { Definition = entity });

        Post post = new Post()
        {
            Title = "foo",
            Description = "bar",
            City = new City { },
            Brokerage = false,
            Location = "",
            RequestedPrice = 500,
            ParentCategory = new Category() { },
            AuthorIPAddress = "",
            Attributes = v
        };

        db.Posts.Add(post);

        var deletedValuesStore = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db)

.ObjectContext.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Deleted);

And saw that deletedValuesStore contains 1 item – the definition. When I’m commenting this line there’s no items in the store.

Do you got any ideas how it can be solved?
Thanks for your time!

  • 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-06-19T02:19:18+00:00Added an answer on June 19, 2026 at 2:19 am

    Ok so I figured it out.
    Just in case somebody is interest, I’ve configured my DbContext mistakenly with Required().WithOptional() relationship instead of one to many – Required().WithMany().
    Because of that, when I’ve assigned existing attribute definition, which was already assigned to a value, to a new value – it automatically marked it as deleted.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.