I want to join multiple tables in Entity framework, Query against that.
Want to assign output of my query to a complex object which don't have any table.
I am getting below error, when i tried to do.
EntityType 'ConstraintFilter' has no key defined. Define the key for this EntityType. ConstraintFilters: EntityType: EntitySet 'ConstraintFilters' is based on type 'ConstraintFilter' that has no keys defined.
How to overcome this??.
Code
[HttpGet]
[EnableQuery]
public IQueryable<DataPoint> GetDataPoints([FromUri] DateTime effectiveDate, [FromUri] string state, [FromUri] string dataPointName = "", [FromUri] ICollection<string> category = null, [FromUri] bool includeConstraints = false, [FromUri] ConstraintFilter constraintFilter = null)
{
return _db.DataPoints.Where(ent =>
ent.EffectiveDate <= effectiveDate && (ent.ExpiryDate == null || ent.ExpiryDate > effectiveDate)
&& ent.DataPointStates.Any(pr => pr.State == state && (pr.EffectiveDate <= effectiveDate && (pr.ExpiryDate == null || pr.ExpiryDate > effectiveDate))))
.Include(ent => ent.DataPointEnumerations)
.Include(ent => ent.DataPointExpressions.Select(dpe => dpe.Expression))
.Include(ent => ent.DataPointValidations.Select(dpv => dpv.Validation))
.Include(ent => ent.DataPointStates)
.Include(ent=>ent.ConstraintFilters)
.ToList().Select(ent => new DataPoint
{
Description = ent.Description,
EffectiveDate = ent.EffectiveDate,
ExpiryDate = ent.ExpiryDate,
Id = ent.Id,
Name = ent.Name,
IsVirtualField = ent.IsVirtualField,
DataPointStates = ent.DataPointStates.Where(ent2 =>
ent2.State == state && ent2.EffectiveDate <= effectiveDate &&
(ent2.ExpiryDate == null || ent2.ExpiryDate > effectiveDate)).ToArray(),
DataPointExpressions = ent.DataPointExpressions.Where(ent2 =>
ent2.EffectiveDate <= effectiveDate &&
(ent2.ExpiryDate == null || ent2.ExpiryDate > effectiveDate)).
Select(de => new DataPointExpression
{
Id = de.Id,
ExpressionId = de.ExpressionId,
DataPointId = de.DataPointId,
EffectiveDate = de.EffectiveDate,
ExpiryDate = de.ExpiryDate,
Expression = de.Expression
}).ToArray(),
DataPointEnumerations = ent.DataPointEnumerations.Where(ent2 =>
ent2.EffectiveDate <= effectiveDate &&
(ent2.ExpiryDate == null || ent2.ExpiryDate > effectiveDate)).ToArray(),
DataPointValidations = ent.DataPointValidations.Where(ent2 =>
ent2.EffectiveDate <= effectiveDate &&
(ent2.ExpiryDate == null || ent2.ExpiryDate > effectiveDate)).ToArray(),
ConstraintFilters = getConditions(),
}).AsQueryable();
}
.Include(ent=>ent.ConstraintFilters)or you need to define a key mapping for it (based on the error message)