the method 'Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSql' is currently not supported

.net asp.net-core-webapi c# entity-framework-core

Question

I have one method like below -

public string SomeMethod() {

    var resultfromdb = from u in dbContext.TableOne.FromSql("Some select query here")
    join rm in dbContext.TableTwo on u.Id equals rm.FId
    select new SomeObject() {
        /* returning some prperty */
    };

    //some business code here
    return someresult;
}

Now, when I write Unit test for this method using Xunit i am facing below error on FromSql method

Error:

Could not parse expression 'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[TableOne]).FromSql(value(Microsoft.EntityFrameworkCore.RawSqlString), __p_0)': This overload of the method 'Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSql' is currently not supported.

Test Method

[Fact]
public void Test_Method()
{
 using (var context = new dbContext())
 {
  //Arrange
   PrefillData(context);//In this method i wll add some dummy data to dbcontext
   //some mocking for other code 

   //Act
   var result = SomeMethod();

   //Assert
   Assert.Equal(expectedString, result);

}

1
1
2/25/2020 11:25:24 AM

Accepted Answer

It seems you are using In-Memory Database. Since it is not a real database, you can't use FromSQL method.

3
2/25/2020 7:13:34 AM

Popular Answer

Change the FromSql to FromSqlRaw

dbContext.TableOne.FromSqlRaw("Some select query here")


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow