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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:40:33+00:00 2026-06-01T06:40:33+00:00

I’m trying to consume an odata feed from a windows phone 7 silverlight client.

  • 0

I’m trying to consume an odata feed from a windows phone 7 silverlight client. Basically is a Many to many data relationship between Groups and Users with a UserGroup table between them. When a User logs in, I need to query for the groups she belongs to using her UserId. My Data classes are as follows

[DataServiceKey("Id")]
public class Group
{
    public Guid Id { get; set; }
    public string GroupTag { get; set; }
    public DateTime DateCreated { get; set; }

    [ForeignKey("GroupOwner")]
    public Guid? GroupOwnerId { get; set; }
    public virtual Person GroupOwner { get; set; }

    public bool IsActive { get; set; }

    public virtual ICollection<GroupUser> GroupUsers { get; set; }
}

[DataServiceKey("Id")]
public class GroupUser
{
    public Guid Id { get; set; }

    [ForeignKey("Group")]
    public Guid GroupId { get; set; }
    public virtual Group Group { get; set; }

    [ForeignKey("Person")]
    public Guid PersonId { get; set; }
    public virtual Person Person { get; set; }
    public bool IsActive { get; set; }
}
 [DataServiceKey("Id")]
public class User
{
    public Guid Id { get; set; }
    public string Username { get; set; }
    public string  Password { get; set; }
    public virtual ICollection<GroupUser> UserGroups { get; set; }
    public virtual ICollection<Group> MyGroups { get; set; }
}

I have tried everything I know to get this result but I keep getting one error after the other no matter what I do. Short of having 2 queries which I don’t want to do because it would be too messy, is there any solution?

——Update——

From the long night of research, I have discovered that odata has the limitation of not supporting ‘Any’ and ‘All’ type queries, so my query would not be possible at this time. What I also discovered from here that my implementation of the poco classes could be slightly modified to represent a many to many relationship without explicitly defining the class in the middle which would potentially help me solve this navigation problem.
I am still in the process of working it out as I am having issues defining the navigation properties but as soon as I have a solution, I’ll put it up here so it can help some other hapless traveler who comes down this path.

  • 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-01T06:40:35+00:00Added an answer on June 1, 2026 at 6:40 am

    So here is how I eventually implemented for my odata service.
    First I had to remodel the data eliminating the normalization table GroupUser and defining the related collection on the objects themselves:

    [DataServiceKey("Id")]
    public class Group
    {
        public Guid Id { get; set; }
        public string GroupTag { get; set; }
        public DateTime DateCreated { get; set; }
    
        [ForeignKey("GroupOwner")]
        public Guid? GroupOwnerId { get; set; }
        public virtual Person GroupOwner { get; set; }
    
        public bool IsActive { get; set; }
    
        //his represents the many-to-many relationship
        public virtual ICollection<User> GroupMembers { get; set; }
    }
    
    
    [DataServiceKey("Id")]
    public class User
    {
      public Guid Id { get; set; }
      public string Username { get; set; }
      public string  Password { get; set; }
    
      //This represents the many-to-many relationship
      public virtual ICollection<Group> MembersOfGroups { get; set; }
    
      //This represents the 'GroupOwner' ForeignKey relationship
      public virtual ICollection<Group> MyGroups { get; set; }
    }
    

    In the datacontext class, I then override the OnModelCreating method as follows

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().HasMany(p => p.MemberOfGroups).
                WithMany(c => c.GroupMembers)
                .Map(t=>t.MapLeftKey("GroupId")
                    .MapRightKey("UserId")
                    .ToTable("GroupUsers"));
    
        }
    

    This basically gives the entity framework some insight into how I want my model defined, thus overriding the conventional implementation. The easiest way in my opinion to understand the above statement is to read it as a statement as follows:

    The User entity can have many (has many) MemberOfGroups, each of which can exist ‘with many’ GroupMembers (hence the many to many relationship), the foreignkey field for the left table (Group) should be called GroupId and for the right table (User) should be called UserId and these should be Mapped to a table called “GroupUsers”.

    If you take a look at the data tables generated by entity framework, you will find a third table called GroupUsers with two columns : UserId and GroupId as combined primary key and each referencing a foreign key relationship with the corresponding entity table.

    With this, you can easily query your odata service as if both collections were one to many relationships of the corresponding parent entity. I hope this helps someone.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.