asp.net mvc - EntityFrameworkCore FromSql method call throws System.NotSupportedException -


so using aspnetcore 1.0 efcore 1.0, both latest releases far aware.

executing query delete object using fromsql method on dbset throws exception. both code , exception below.

public void deletecolumn(int p_columnid) {     int temp = p_columnid;     string query = "delete columns id = {0}";     var columnslist = m_context.columns.fromsql(query, p_columnid).tolist();     foreach (columns c in columnslist)     {         m_context.columns.remove(c);     }      m_context.savechanges(); } 

after executing fromsql call, following exception

an exception of type 'system.notsupportedexception' occurred in remotion.linq.dll not handled in user code  additional information: not parse expression 'value(microsoft.entityframeworkcore.query.internal.entityqueryable`1[aspnet5_scrum_tool.models.columns]).fromsql("delete columns id = {0}", __p_0)': overload of method 'microsoft.entityframeworkcore.relationalqueryableextensions.fromsql' not supported. 

i have no clue how fix error , googling have come across no similar problems.

i wondering, if query/code successful return 'iqueryable object. solely contain results of query, in case specific column object delete?

fromsql intended allow compose custom sql select statement return entities. using delete statement not appropriate here, since goal load records want delete , delete them using default entity framework mechanism. delete statement not return records deleted (though there ways accomplish that). if did, records deleted , won't want iterate on them , remove on them.

the straightforward way want might use removerange method in combination where query.

public void deletecolumn(int p_columnid) {    m_context.columns.removerange(m_context.columns.where(x => x.id == p_columnid))         m_context.savechanges(); } 

alternately, if want load entities , iterate manually through them

public void deletecolumn(int p_columnid) {     columnlist = m_context.columns.where(x => x.id == p_columnid);     foreach (columns c in columnslist)     {         m_context.columns.remove(c);     }      m_context.savechanges(); } 

if want issue delete statement manually, suggested mike brind, use executesqlcommand method similar to:

public void deletecolumn(int p_columnid) {     string sqlstatement = "delete columns id = {0}";     m_context.database.executesqlcommand(sqlstatement, p_columnid); } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -