Need help in querying many to many relationship.
I have 3 tables
1] Games
| GameID | Game Title |
| 1 | FIFA 10 |
| 2 | Halo 3 |
| 3 | DIRT |
2] Platforms
| PlatformID | PlatformName |
| 1 | XBox 360 |
| 2 | PS3 |
| 3 | PSP |
| 4 | Wii |
3] GamePlatforms
| GameID | PlatformID |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 2 | 3 |
Now i need to query All Games in PlatformID X
POCO
public class Game
{
[Key]
public int GameId { get; set; }
[Column("GameTitle")]
public string Title { get; set; }
public virtual ICollection
}
public class Platform
{
[Key]
public int PlatformId { get; set; }
[Column("Platform")]
public string Name { get; set; }
public virtual ICollection
}
// Mapping
modelBuilder.Entity
.HasMany(u => u.Platforms)
.WithMany()
.Map(a =>
{
a.ToTable("GamePlatforms");
a.MapLeftKey("GameId");
a.MapRightKey("PlatformId");
});
Service Layer
public IEnumerable
{
Platform _platform = platformRepository.Get(platformId);
var predicate = PredicateBuilder.True
predicate = predicate.And(mg => mg.Game.Platforms.Contains(_platform)).And(mg => mg.Game.Title == gameName).Or(mg => mg.Game.Title.Contains(gameName));
return repository.GetMany(predicate);
}
Data Layer
public virtual IEnumerable
{
return _dbSet.Where(where).ToList();
}
throws an error Unable to create a constant value of type 'XXXX.BO.Platform'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
Please help me to solve the problem.
Thanks inadvance
Satish

Suthish NairPosted Jun 24, 2011, 9:51 AM