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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:47:51+00:00 2026-05-15T10:47:51+00:00

This has been driving me nuts for a week now. I have a class

  • 0

This has been driving me nuts for a week now.

I have a class that looks like this:

public class SuggestionVote
{
   public virtual int ID { get; set; }
   public virtual Suggestion Suggestion { get; set; }
   public virtual User User { get; set; }
   public virtual VoteTypeWrapper VoteType { get; set; }
   public virtual DateTime DateVoted { get; set; }

   // Equality overrides omitted
}

VoteTypeWrapper is actually an enum wrapper based on an article on how to fake enums in Entity Framework 4 and looks like this:

public class VoteTypeWrapper
{
        private VoteType _type;
        
        public int Value
        {
            get { return (int)_type; }
            set { _type = (VoteType)value; }
        }

        public VoteType EnumValue
        {
            get { return _type; }
            set { _type = value; }
        }

        public static implicit operator VoteTypeWrapper(VoteType voteType)
        {
            return new VoteTypeWrapper { EnumValue = voteType };
        }

        public static implicit operator VoteType(VoteTypeWrapper voteTypeWrapper)
        {
            return voteTypeWrapper == null ? VoteType.NotVoted : voteTypeWrapper.EnumValue;
        }
}

with the VoteType enumeration being:

public enum VoteType
{
   Up,
   Down,
   NotVoted
}

I’ve also defined a ComplexType in the model designer:

<ComplexType Name="VoteTypeWrapper" >
   <Property Type="Int32" Name="Value" Nullable="false" />
</ComplexType>

The voting system I’m implementing works somewhat like StackOverflow’s voting system: The user can vote up or down; voting a second time undoes the previous vote, and voting in the opposite direction (i.e., down when previously voted up) undoes the vote as well.

Now for the problem. Voting once works like a charm and all the values are correctly saved to the database. Undoing a vote, however, refuses to work. To undo a vote I basically mark the vote to undo for deletion and then call SaveChanges on the context.
As soon as I do that an InvalidOperationException occurs giving me the following message:

The entity of type 'System.Data.Entity.DynamicProxies.SuggestionVote_4A3949F5B95E9A51567509467230FD7CEA0FB7761C3AC9C8C2BBC62BCAA033AF' 
references the same complex object of type 'Web.Model.VoteTypeWrapper' more than once. 
Complex objects cannot be referenced multiple times by the same entity.

I just don’t get it. Down anyone know what I could be doing wrong? I’ve been Googleing for day but to no avail

  • 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-15T10:47:51+00:00Added an answer on May 15, 2026 at 10:47 am

    Well, I’ve finally decided to work around it but simply mapping an int property instead of a ComplexType. I have also added a (non-mapped) helper property to avoid having to cast constantly from int to VoteType.

    I would still love to get an answer for my problem so if you can help it I would appreciate it. I’ll give it a couple of days before I mark my own answer as correct.

    EDIT: Since I’ve gotten no answer whatsoever to this, m marking my own answer as good.

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

Sidebar

Related Questions

This has been driving me nuts all day. I have a weird bug that
This has been driving me absolutely nuts. I have a substitute function like this:
This one has been driving me nuts. I have a div that has it's
I have a javascript function that has been driving me nuts. This is the
This one has been driving me nuts for a few days now and I've
This error has been driving me nuts. We have a server running Apache and
So this has just been driving me nuts! I have looked through tons of
This has been driving me nuts for hours now. Consider the following test script
This has been driving me nuts for the past hour. I have two computers,
I have a problem that has been driving me nuts for days.. I've tried

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.