我试图在EF Core中应用加入,但它返回了错误的数据。
如果我在SQL Server中运行以下查询,则返回无结果,即预期的行为。
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%'
但是当我尝试从C#应用程序运行相同的输入值的类似代码时,它返回一行。
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
});
退回记录
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',& #39; 0',NULL,NULL, ' 1',' 1',' asdasdasd',' asdasd',' dasasd',' sdasd& #39;,' 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&# 39 ;, ' asdas',' dsfdsf',' dsfd',' fdsdf',' 21',' AASAS& #39;,' 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
更新
返回包含较少列的记录
Id,DeviceCode,DeviceDesc,DeviceName,StoreId,StoreName, CategoryId,CategoryName' 3',' asdasd',' asdasd',' asdasd',' 1', ' dsfd',' 21',' asS'