# NonIQuerableAnalyzer **Repository Path**: hzgel/NonIQuerableAnalyzer ## Basic Information - **Project Name**: NonIQuerableAnalyzer - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-12 - **Last Updated**: 2024-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # NonIQuerableAnalyzer Prevents IQueryable from using parent class extension methods NuGet: https://www.nuget.org/packages/NonIQuerableAnalyzer In EF Core 3.1, if the IQuerable object uses its own IEnumerable extension method, it will prompt untranslatable statements at runtime. To solve this situation, it is necessary to detect it in advance during the compilation phase # How to use it ## Declare a Attribute - The analyzer checks the attribute only by name - any namespace, ``` using System; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] internal class NonIQueryableAttribute : Attribute { } ``` ## case1 : apply a Method ``` public static class EnumerableExtensions { [NonIQueryableAttribute] public static IEnumerable OrderByExpression(this IEnumerable source, int a) { // balabala..... return source; } } ``` ## case2 :apply all Method ```c# [NonIQueryableAttribute] public static class EnumerableExtensions { public static IEnumerable OrderByExpression(this IEnumerable source, int a) { return source; } } ``` ## Misuse ### case1 ```c# class Program { static void Main() { IQueryable query = null; var queryableResult = query.OrderByExpression(1); // error } } ``` ![image](https://github.com/HZ-GeLiang/NonIQuerableAnalyzer/assets/16562680/294bd349-8935-47af-98b5-2e7e8c46b744) ### case2 ```c# { IQueryable query = null; query.Where(a => a.Name.IsEqualAnyIgnoreCase("abc")); //error } ``` ![image](https://github.com/user-attachments/assets/b5ba045c-a268-466a-813d-2c5e53301f4c)