while updating a record I want o add where clause .I dont want to use the default primary keys as declared in entity . :?:
8 Answer(s)
-
0
EntityFramework itself has not such a feature. You can try to use 3rd party libraries, like <a class="postlink" href="https://github.com/loresoft/EntityFramework.Extended">https://github.com/loresoft/EntityFramework.Extended</a>
-
0
can it be used with abp repositories?
-
0
You can add custom methods to your repositories (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/EntityFramework-Integration#DocCustomRepositoryMethods">http://www.aspnetboilerplate.com/Pages/ ... oryMethods</a>)
-
0
using <a class="postlink" href="https://github.com/loresoft/EntityFramework.Extended">https://github.com/loresoft/EntityFramework.Extended</a> gives following errors
Error 4 'System.Linq.IQueryable' does not contain a definition for 'PageBy' and no extension method 'PageBy' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?) C:\Users\nishi_000\Desktop\projects\diam\Ni.diam.Application\MultiTenancy\TenantAppService.cs 44
Error 8 'System.Linq.IQueryable' does not contain a definition for 'PageBy' and no extension method 'PageBy' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?) C:\Users\nishi_000\Desktop\projects\diam\Ni.diam.Application\Authorization\Users\UserAppService.cs 66
Error 11 Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable<Ni.diam.Authorization.Users.LinkedUserDto>'. An explicit conversion exists (are you missing a cast?) C:\Users\nishi_000\Desktop\projects\diam\Ni.diam.Application\Authorization\Users\UserLinkAppService.cs 121 Error 13 Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable<Ni.diam.Localization.Dto.LanguageTextListDto>'. An explicit conversion exists (are you missing a cast?) C:\Users\nishi_000\Desktop\projects\diam\Ni.diam.Application\Localization\LanguageAppService.cs 163
-
0
Add "using Abp.Linq.Extensions;" to your code file in order to access PageBy extension method.
-
0
I added that now error is with OrderBy
query.OrderBy(input.Sorting)
-
0
Hi,
There is an open issue about this problem for EntityFramework.Extended library on github. <a class="postlink" href="https://github.com/loresoft/EntityFramework.Extended/issues/114">https://github.com/loresoft/EntityFrame ... issues/114</a>
For now it seems, it's not possible to use EntityFramework.Extended library.
You can fork EntityFramework.Extended library and change the name of OrderBy method but it will bring you an extra work for keeping synchronized your version with EntityFramework.Extended master.
-
0
OK, it seems there are two extension method with same name in same namespace and same class, but in different assemblies. We can use some reflection to call OrderBy in a desired assembly.
- Create your own OrderBy extension method:
public static class DynamicQueryableExtensions { private static readonly MethodInfo _orderByMethod; static DynamicQueryableExtensions() { var dynamicQueryableType = Type.GetType("System.Linq.Dynamic.DynamicQueryable, System.Linq.Dynamic"); _orderByMethod = GetMethodEx(dynamicQueryableType, "OrderBy", new[] { typeof (IQueryable<>), typeof(string), typeof(object[]) }, 1); } public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) { return (IQueryable<T>) _orderByMethod .MakeGenericMethod(typeof (T)) .Invoke(null, new object[] {source, ordering, values}); } public static MethodInfo GetMethodEx(this Type type, string name, Type[] parameterTypes, int genericTypeCount = 0) { var methods = type.GetMethods(); foreach (var method in methods.Where(m => m.Name == name)) { if (method.IsGenericMethodDefinition && method.GetGenericArguments().Length != genericTypeCount) { continue; } var methodParameterTypes = method.GetParameters().Select(p => p.ParameterType); if (!methodParameterTypes.SequenceEqual(parameterTypes, new SimpleTypeComparer())) { continue; } return method; } return null; } private class SimpleTypeComparer : IEqualityComparer<Type> { public bool Equals(Type x, Type y) { return x.Assembly == y.Assembly && x.Namespace == y.Namespace && x.Name == y.Name; } public int GetHashCode(Type obj) { throw new NotImplementedException(); } } }
Create this class in a namespace in your application, say MyCompanyName.MyProjectName.Extensions namespace. I suggest you to add into Core project
- Remove "using System.Linq.Dynamic;" from your code and add "using MyCompanyName.MyProjectName.Extensions;".
That's all. It will work.