Column of boolean always return false in sql query

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

Question

net mvc core 2.2 and Mssql.I wrote a stored procedure which is working fine. The result:

Result of stored procedure in sql server

However whenever I run my app all of stockPermit column returns false.

Controller

if (!String.IsNullOrEmpty(searchString))
{
    searchString = Methods.RemoveTurkish(searchString);
    bayiVM.JoinedTable = await _adb.CariUserJoin.FromSql("EXECUTE CariListeAra {0}", searchString).ToListAsync();
}
else
{
    bayiVM.JoinedTable = await _adb.CariUserJoin.FromSql("EXECUTE CariListeGetir").ToListAsync();
}

var count = bayiVM.JoinedTable.Count;
bayiVM.JoinedTable = bayiVM.JoinedTable.Skip((productPage - 1) * PageSize).Take(PageSize).ToList();

bayiVM.PagingInfo = new PagingInfo
{
    CurrentPage = productPage,
    ItemsPerPage = PageSize,
    TotalItems = count,
    urlParam = param.ToString()
};

return View(bayiVM);

Result in Debug:

Debug screenshot

What can cause this problem. I appreciate any help.Thank you.

Stored Procedure1

ALTER PROCEDURE [dbo].[CariListeGetir]
AS
BEGIN

    SELECT [CARI_KOD], [CARI_ISIM], [LockoutEnd],[PlaKodu], [StockPermit] FROM YESLAS2018.dbo.TBLCASABIT
    left join b2byeslasDb.dbo.AspNetUsers on TBLCASABIT.CARI_KOD=AspNetUsers.UserName
END

stored procedure2

ALTER PROCEDURE [dbo].[CariListeAra] (@ad nvarchar(15))
AS
BEGIN

    SELECT [CARI_KOD], [CARI_ISIM], [LockoutEnd],[PlaKodu], [StockPermit] FROM YESLAS2018.dbo.TBLCASABIT
    left join b2byeslasDb.dbo.AspNetUsers on TBLCASABIT.CARI_KOD=AspNetUsers.UserName
    where CARI_KOD like '%'+@ad+'%' or CARI_ISIM like '%'+@ad+'%'

END

My view model

public class BayiVewModel
    {
        public List<CariUserJoin> JoinedTable { get; set; }
        public PagingInfo PagingInfo { get; set; }
    }

CariUserJoin:

public class CariUserJoin
    {
        [Key]
        public string CARI_KOD { get; set; }
        public string CARI_ISIM { get; set; }
        public DateTimeOffset? LockoutEnd { get; set; }
        public string PlaKodu { get; set; }
        public bool StockPermit { get;set}

    }

PS:I used LEFT JOIN. I mean left table has 4500 rows and right table has 30.

1
-2
1/18/2019 12:10:45 PM

Accepted Answer

Please use:

public bool? StockPermit { get; set; }

set; is needed so that the property can actually be set. ? is needed to make it nullable.

2
1/16/2019 1:04:35 PM


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