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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:11:32+00:00 2026-05-22T23:11:32+00:00

There’s a many-to-many UserFeed table that stands between User and Feed and denotes a

  • 0

There’s a many-to-many UserFeed table that stands between User and Feed and denotes a twitter-like follow relationship.
It only has two fields, which form a composite key: UserID and FeedID.

I need to write a method that will subscribe or unsubscribe a user from a feed based on a boolean flag.

public void SetSubscriptionFlag (int userId, int storeId, bool subscribe)
{
}

I’m new to Entity Framework so I’m trying to find and follow an “EF-ish” way to accomplish this.

My initial thoughts are:

  • Instead of working with the middle UserFeed class, I should create a many-to-many Subscriptions property (EDIT: hit limitations here);
  • After I’ve done so, I’ll need to fetch a User instance by ID, check whether it has given Feed in its Subscriptions and add/delete it depending on the flag and current existence;
  • Figure out how to avoid racing conflicts when there is a time interval before the check and adding/deleting and user manages to submit two adding or deletion requests;
  • Optimize my code as to avoid unneccessary SELECTs, if any occur, because all I really want to do is a single SELECT and single INSERT/DELETE.

A relevant code snippet and comment on my points is highly appreciated.

Thanks!

  • 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-22T23:11:33+00:00Added an answer on May 22, 2026 at 11:11 pm

    You can use dummy objects – it definitely works for insert and I hope it can be used for delete as well:

    Create new relation:

    var user = new User() { Id = userId };
    context.Users.Attach(user);
    var store = new Store() { Id = storeId };
    context.Stores.Attach(store);
    
    // Now context trackes both entities as "existing"
    // and you can build a new relation
    user.Subscriptions.Add(store);
    context.SaveChanges();
    

    Remove existing relation:

    var user = new User() { Id = userId };
    var store = new Store() { Id = storeId };
    user.Subscriptions.Add(store);
    context.Users.Attach(user);
    
    // Now context trackes both entities as "existing"
    // with "existing" relation so you can try to remove it
    user.Subscriptions.Remove(store);
    context.SaveChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a field in my company's Contacts table. In that table, there is
There is a table view with three sections. The last section may contain many
There are many tutorials that talk about deleting index.php from the url. But I
There are many methods to override, like initWithNibname: , awakeFromNib , loadView , viewDidLoad
There is a conversion process that is needed when migrating Visual Studio 2005 web
There seem to be many ways to define singletons in Python. Is there a
There are a few ways to get class-like behavior in javascript, the most common
There are several shading languages available today like GLSL, HLSL, CG, which one to
There are many string matching algorithms can be used to find a pattern (string)
I've got a string that has curly quotes in it. I'd like to replace

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.