I am getting different kind of errors.
let me show my update logic now.
this is my updated model
[Keyless]
public class FranchiseWebInquiry
{
public int FranchisesId { get; set; }
public int SubOfficeId { get; set; }
public string FranchiseName { get; set; }
public string SubOfficeName { get; set; }
public string Code { get; set; }
public string PickupId { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string PostCode { get; set; }
public string PrimaryContact { get; set; }
public string Email { get; set; }
public string Town { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public class FranchiseRespository : IDisposable, IFranchiseRespository
{
private readonly CarRentalContext _dbContext;
private readonly ILogger<FranchiseRespository> _logger;
public FranchiseRespository(ILogger<FranchiseRespository> logger, CarRentalContext context)
{
_dbContext = context;
_logger = logger;
}
public Task<List<FranchiseWebInquiry>> SearchFranchisesWebInquiryRes(string keyword)
{
try
{
var items = _dbContext.GetFranchiseList(keyword);
return items;
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
return null;
//throw;
}
}
public void Dispose()
{
// Dispose of unmanaged resources.
_dbContext.Dispose();
//_logger = null;
// Suppress finalization.
GC.SuppressFinalize(this);
}
public void WriteMessage(string message)
{
_logger.LogInformation($"MyDependency2.WriteMessage Message: {message}");
}
}
public interface IFranchiseRespository
{
void WriteMessage(string message);
Task<List<FranchiseWebInquiry>> SearchFranchisesWebInquiryRes(string keyword);
}
public class CarRentalContext : DbContext
{
public CarRentalContext(DbContextOptions<CarRentalContext> options)
: base(options)
{
}
public DbSet<FranchiseWebInquiry>? Franchises { get; set; }
public virtual Task<List<FranchiseWebInquiry>> GetFranchiseList(string keyword)
{
return this.Set<FranchiseWebInquiry>()//.FromSqlInterpolated<FranchiseWebInquiry>($"EXECUTE dbo.GetFranchisesForWeb({keyword})")
.FromSqlRaw("EXECUTE dbo.GetFranchisesForWeb {0}", keyword)
.AsNoTracking()
.ToListAsync();
}
}
Remaining files have already been shared above.
and this is the stored procedure (This is an example and doesn't contain full logic in it)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetFranchisesForWeb]
@pStrSearchQuery NVarChar(1000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT Distinct [t0].[Id] AS [FranchisesId], null AS [SubOfficeId], CONCAT( 'F-', [t0].[Id]) AS [PickupId], [t0].[Name] AS [FranchiseName], null AS [SubOfficeName], [t0].[Code], [t0].[Address1], [t0.[Address2], [t0].[Address0], [t0].[Postcode] AS [PostCode], [t0].[Number] AS [PrimaryContact],
[t0].[Email], [t0].[Name] AS [Town], [t0].[Latitude], [t0].[Longitude]
FROM [Franchise] AS [t0]
[t0].[Title] = @pStrSearchQuery;
END
and Currently I am getting this error message in catch block
Data is Null. This method or property cannot be called on Null values.
I want to use Either FromSqlInterpolated or FromSqlRaw . Can we fix it ?