I want to develop an analyzer to automatically identify entity framework related antipatterns. For example, the following is an example of loading redundant columns.
File: DataContext.cs
/// returns all users with all columns
public Collection<Student> GetTopStundets()
{
return dbContext.Students.ToArray();
}
File: View.cs
/// Print Top Students' Names
public Collection<Student> GetTopStundets()
{
var dataContext = new DataContext();
var students = dataContext.GetTopStudents();
foreach(vat student in students)
{
Console.WriteLine(student.Name);
}
}
As you can see we are loading all columns while we are using only the Name column. Could you please help how can I identify such patterns by employing CFG and DFG graphs? Is it possible to detect these kinda patterns in code using Roslyn?
Hi @sharwell. Would you please give me a hint on this question? is it doable?
The CFG is a new feature. @mavasani should be able to provide information about its current state. 馃槃
@mirsaeedi We do not have CFG/DFA APIs currently for you to write such an analyzer. We are working towards exposing an IOperation based CFG in near future and build upon that to expose a DFA framework to write custom dataflow analyses to track custom information. We will keep you in loop...