I'm trying to apply join in EF Core, but it's returning wrong data.
If I run the below query in SQL Server it returns no results, its expected behavior.
select * from device d
inner join store s on s.Id = d.StoreId
inner join category c on c.Id = d.CategoryId
where s.StoreName like '%dsfd%' and c.CategoryName like '%asdasdasd1%'
But When I try to run the similar code from the C# application for the same input values, it returns one row.
var serachresult = (from devices in _deviceRepository.GetAll()
join stores in _storeRepository.GetAll() on devices.StoreId equals stores.Id
join categories in _categoryRepository.GetAll() on devices.CategoryId equals categories.Id
where
(!string.IsNullOrWhiteSpace(searchInput.StoreName) ? stores.StoreName.Contains(searchInput.StoreName) : true) &&
(!string.IsNullOrWhiteSpace(searchInput.CategoryName) ? categories.CategoryName.Contains(searchInput.CategoryName) : true)
select new DeviceDetailsDto
{
Id = devices.Id,
DeviceName = devices.DeviceName,
DeviceDesc = devices.DeviceDesc,
DeviceCode = devices.DeviceCode,
StoreId = devices.StoreId,
CategoryId = devices.CategoryId,
CategoryName = categories.CategoryName,
StoreName = stores.StoreName
});
Returned record
Id, AssetID, CategoryId, CreationTime, CreatorUserId, DeleterUserId, DeletionTime, DeviceCode, DeviceDesc, DeviceName, FlgActive, IsDeleted, LastModificationTime, LastModifierUserId, StoreId, Id, AddressLine1, AddressLine2, City, Country, CreationTime, CreatorUserId, DeleterUserId, DeletionTime, EmailAddress, FlgActive, IsDeleted, LastModificationTime, LastModifierUserId, PhoneNo, PostalCode, State, StoreDesc, StoreName, StoreNo, Id, CategoryDesc, CategoryName, CreationTime, CreatorUserId, DeleterUserId, DeletionTime, FlgActive, ImageName, ImagePath, IsDeleted, IsLast, LastModificationTime, LastModifierUserId, Level, ParentId, StoreId, TemplatesTypesId '3', '123123123', '21', '2018-05-14 18:02:58.480972', '2', NULL, NULL, 'asdasd', 'asdasd', 'asdasd', '1', '0', NULL, NULL, '1', '1', 'asdasdasd', 'asdasd', 'dasasd', 'sdasd', '2018-05-09 17:14:47.141586', '1', '0', '2018-05-10 11:48:34.897152', 'dasdasd@gmail.com', '0', '0', NULL, NULL, 'asdsadsa', 'dasdasd', 'asdas', 'dsfdsf', 'dsfd', 'fdsdf', '21', 'AASAS', 'asS', '2018-05-10 11:30:05.237959', '1', NULL, NULL, '0', 'img2.jpg', 'C:\workspace\src\Nec.Spar.Web.Host\img2.jpg', '0', '1', NULL, NULL, '0', '0', '1', NULL
Update:
Returned record with less columns
Id | DeviceCode | DeviceDesc | DeviceName | StoreId | StoreName | CategoryId | CategoryName |
---|---|---|---|---|---|---|---|
3 | asdasd | 'asdasd' | 'asdasd' | '1' | dsfd | '21' | 'asS' |