When Using LINQ to get information I use the following method
var salt_water_disposals = _SaltWaterDisposals.SaltWaterDisposals.Select(sw => new SaltWaterModel
{
saltwater_ID = sw.SaltWaterDisposalID,
lease = sw.Lease.LeaseName,
field = sw.Lease.Field.Name.ToLower(),
permitter_fluid = sw.PermittedFluids.Count == 0 ? "None" : sw.PermittedFluids.Aggregate("", (current, c) => current+c.Fluid.Name),
max_gas_pressure = sw.MaxGasInjectionPressure,
});
However when I run the code I get the following error because of the PermittedFluids:
LINQ to Entities does not recognize the method ‘System.String
Aggregate[PermittedFluid,String](System.Collections.Generic.IEnumerable1[FieldPro.Domain.Entities.PermittedFluid],3[System.String,FieldPro.Domain.Entities.PermittedFluid,System.String])’
System.String,
System.Func
method, and this method cannot be translated into a store expression.
I have tried using it also as a ToString() but I get the same error.
Any Ideas?
Any Help would be appreciated.
I fixed this by taking out the Aggregate call and calling it in my view, and changing the data type or permitter_fluid.
So My model has:
My Controller has:
and my view has (using a Html.Grid from MvCContrib):
This solved my problem