I am working on a project where we use WCF and Entity Framework. Because WCF wouldn't work with dynamic proxies, taken from here, I have put this line in the constructor of my context class:
public CarBatteryEntities() : base("name=CarBatteryEntities")
{
base.Configuration.ProxyCreationEnabled = false;
}
WCF works, however my linq queries wouldn't return their associations.
This is my code:
List<Edge> edges = edgeRepository.GetBatteryCenterEdges("cityname").ToList();
foreach(var e in edges)
Console.WriteLine(e);
Class Edge
has 3 main variables - BatteryStation
, BatteryStation
and distance
.
It is an auto-generated class from the ET, both BatteryStation
are connections to the other table.
If I use ProxyCreationEnabled
as true
everything works as a charm.
If I use ProxyCreationEnabled
as false
only distance
would be returned correctly and both objects (BatteryStation
and BatteryStation1
) will be null
.
Any suggestions?
public IList<Edge> GetBatteryCenterEdges(string name)
{
var query = context.Edge
.Where(edge => edge.BatteryStation.name.Equals(name)
|| edge.BatteryStation1.name.Equals(name))
.AsEnumerable()
.SelectMany(edge => new[] {
edge,
new Edge() {
BatteryStation = edge.BatteryStation1,
BatteryStation1 = edge.BatteryStation,
distance = edge.distance
}
});
return query.ToList();
}