0

I am essentially am trying to find a clean way to pull in data from another table. Below is a simplified version of my model. My goal is to put the platform name in the userplatform. I would like the cleanest way to do this so I assume with automapper or directly in my repository.

When I try to put a virtual reference to Platform in User Platform my code gets an error that we have a loop of cascading deletes.

Any ideas on how to resolve this problem?

public class User
{
    public int UserID { get; set; }
    public virtual ICollection<UserPlatform> UserPlatform { get; set; }
}
public class UserPlatform
{
    public int UserPlatformID { get; set; }
    public String PlatformName { get; set; }
    public int UserID { get; set; }
}

public class Platform
{
    public int PlatformID { get; set; }
    public string Name { get; set; }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
David Corrado
  • 363
  • 3
  • 19
  • You don't specify what layers you have, and in what layer you need this. Personally I would avoid automapper. This aggregation should be done in your service layer (in case of data contracts) or client (in case of view models), but again, you should give more information about your architecture. – L-Four Apr 08 '13 at 13:22

1 Answers1

0

Alternatives

  1. Db: Denormalize your data so that the information is stored in your user table.
  2. Repository: Do a join inside
  3. Repository: Do two different queries and manually build the User object.
jgauffin
  • 99,844
  • 45
  • 235
  • 372