using Angular QueryBuilder.getSqlFromRules() in the backend with System.Linq.Dynamic.Core (EF core 3.1)

I tried using the output of angular queryBuilder.getSqlFromRules() on the backend with System.Linq.Dynamic.Core (EF core 3.1) and I got a Syntax error Exception.

Dow you have any guidance to assist me use the client side generated SQL with EF core 3.1 or is this use case not supported.

1 Reply 1 reply marked as answer

MV Madhan Venkateshan Syncfusion Team June 18, 2020 02:21 PM UTC

Hi EMOVON UWADIA, 
 
Good day to you. 
 
You can use ‘FromSqlRaw’ method from ‘Microsoft.EntityFrameworkCore’ to execute sql query generated using query builder. Please refer the below code snippets and sample link. 
 
WeatherForecastController.cs 
[HttpGet] 
        public IEnumerable<Publisher> Get(string sqlRule) 
        { 
            using (var _context = new BookStoresDBContext()) 
            { 
                if (sqlRule != null) 
                { 
                    return _context.Publishers.FromSqlRaw("SELECT * FROM Publishers WHERE " + sqlRule).ToList(); 
                } else 
                { 
                    return _context.Publishers.ToList(); 
                } 
            } 
             
        } 
 
 
 
 
Regards, 
Madhan V 


Marked as answer
Loader.
Up arrow icon