The type of one of the expressions in the join clause is incorrect in Entity Framework

The types and the names of the properties in the anonymous types must match: new { p1 = q.QOT_SEC_ID, p2 = dpr.DPR_TS } equals new { p1 = (decimal)p.PAY_SEC_ID, p2 = p.PAY_DATE } or if p.PAY_SEC_ID were an int?: new { p1 = (int?)q.QOT_SEC_ID, p2 = dpr.DPR_TS } equals new { p1 = p.PAY_SEC_ID, p2 … Read more

The specified type member is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

You cannot use properties that are not mapped to a database column in a Where expression. You must build the expression based on mapped properties, like: var date = DateTime.Now.AddYears(-from); result = result.Where(p => date >= p.DOB); // you don’t need `AsQueryable()` here because result is an `IQueryable` anyway As a replacement for your not … Read more

‘Contains()’ workaround using Linq to Entities?

Update: EF ≥ 4 supports Contains directly (Checkout Any), so you don’t need any workaround. public static IQueryable<TEntity> WhereIn<TEntity, TValue> ( this ObjectQuery<TEntity> query, Expression<Func<TEntity, TValue>> selector, IEnumerable<TValue> collection ) { if (selector == null) throw new ArgumentNullException(“selector”); if (collection == null) throw new ArgumentNullException(“collection”); if (!collection.Any()) return query.Where(t => false); ParameterExpression p = selector.Parameters.Single(); … Read more

LINQ to Entities does not recognize the method ‘System.String Format(System.String, System.Object, System.Object)’

Entity Framework is trying to execute your projection on the SQL side, where there is no equivalent to string.Format. Use AsEnumerable() to force evaluation of that part with Linq to Objects. Based on the previous answer I have given you I would restructure your query like this: int statusReceived = (int)InvoiceStatuses.Received; var areaIds = user.Areas.Select(x=> … Read more

Method cannot be translated into a store expression

Reason: By design, LINQ to Entities requires the whole LINQ query expression to be translated to a server query. Only a few uncorrelated subexpressions (expressions in the query that do not depend on the results from the server) are evaluated on the client before the query is translated. Arbitrary method invocations that do not have … Read more

C# – code to order by a property using the property name as a string [duplicate]

I would offer this alternative to what everyone else has posted. System.Reflection.PropertyInfo prop = typeof(YourType).GetProperty(“PropertyName”); query = query.OrderBy(x => prop.GetValue(x, null)); This avoids repeated calls to the reflection API for obtaining the property. Now the only repeated call is obtaining the value. However I would advocate using a PropertyDescriptor instead, as this will allow for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)