I'm trying to access/use raw Sql script or use stored procedure in C# .Net Core Razor page. I know my sql script/stored procedure works upon getting the script on debug mode and then trying it out in MS SQL Server Management Studio.
I always get NullReferenceException: Object reference not set to an instance of an object on this code:
var bom = _context.Recipe
.FromSqlRaw("EXEC sproc_GetBOM @itemcode", _itemCode)
.AsNoTracking()
.ToList();
This is my context
public partial class MyDBContext: IdentityDbContext
{
public MyDBContext()
{
}
public MyDBContext(DbContextOptions<MyDBContext> options)
: base(options)
{
}
public DbSet<Recipe> Recipe { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Server=serverIp; Database=DB; Integrated Security = False; Trusted_Connection=False; MultipleActiveResultSets=True; User Id=UserId;Password=Password;");
}
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder){
//
}
Any idea what am I doing wrong? Thank you in advance.