How to apply a filter in a LINQ to SQL expression only if results exist when the filter is applied?
Tag : chash , By : user121350
Date : March 29 2020, 07:55 AM
will help you I have a function I'd like to transform into a LINQ to SQL expression, but I can't figure out how. This function is called from within a LINQ query, once for each row in the result set. The productAreaId being passed in may or may not refer to valid data, so I have to check, and then only filter by productAreaId if any rows exist after applying the filter: , Maybe something like this: var customerData =
from c in db.Customers
let orders = db.Orders.Where(o => o.OrderNumber == c.orderNumber &&
o.Group.GroupTypeId != (int)GroupTypeId.INTERNAL &&
!o.Deleted)
let orders2 = orders.Where(o => o.ProductAreaId == c.productAreaId)
select new
{
id = c.Id,
name = c.Name,
lastOrder = c.productAreaId != null && orders2.Any() ?
orders2.FirstOrDefault() :
orders.FirstOrDefault()
};
|
google-app-engine: How to apply filter in query when filter parameter is db.ReferenceProperty?
Tag : python , By : Vorinowsky
Date : March 29 2020, 07:55 AM
With these it helps You can only use filter on indexed attributes. person.name is from other entity! In sql you would need to use join (which is impossible when data grows big), in google bigtable like in many other non-relational databases tables join is not possible. Luckily your case is very simple, you can select all cars if you know persons key: >>> person = Person.all().filter('name =', 'Mr. Random').fetch(1)[0]
>>> cars = Car.all().filter('person =', person.key())
Class Car(db.Model):
...
person = db.ReferenceProperty(Person, collection_name='cars_collection')
>>> person = Person.all().filter('name =', 'Mr. Random').fetch(1)[0]
>>> mrs_randoms_cars = person.cars_collection
|
angularjs apply filter cross nested directive (filter also apply on child even it doesn't match parent)?
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Since you want parents to be visible if any of it's children are visible - one option is to add a property to each node in the tree (akin to how ngRepeat adds $$hashKey) indicating whether that node matched the test and is visible, or not. I'll call that property show in the code below. Then, when a search is done, each node's show property is set. Then parents can check all their children to see if any of them are visible. function checkChildren(nextl) {
var i, showNode=false;
if (nextl) {
for (i = 0;i < nextl.length;i++)
showNode |= nextl[i].show | checkChildren(nextl[i].children);
}
return showNode;
}
// Filter
scope.tree_filter = function(obj) {
var reg = new RegExp(scope.search, 'i');
var showNode = !scope.search || reg.test(obj.name);
obj.show = showNode;
return (showNode | checkChildren(obj.children)) ;
};
|
Apply.prototype.push.apply vs forEach for nested arrays?
Date : March 29 2020, 07:55 AM
like below fixes the issue So I am doing learnRx http://reactive-extensions.github.io/learnrx/ and I have a question about making the mergeAll() function (question 10). , It took me awhile to understand why it works Array.prototype.mergeAll = function() {
return Array.prototype.concat.apply([], this);
};
|
Javascript how to filter an array using forEach() inside filter()
Date : March 29 2020, 07:55 AM
With these it helps You can iterate the fields using Array#some, and if one of them is equal to value return the item: const array_one = [
{id: 1, code: 'ABC123', name: 'John'},
{id: 2, code: 'DEF456', name: 'Stew'}
];
const array_two = [
{id: 1, value: '012345', company: 'Company 01' },
{id: 2, value: '678910', company: 'Company 02' }
];
const filterArray = (array, fields, value) => {
fields = Array.isArray(fields) ? fields : [fields];
return array.filter((item) => fields.some((field) => item[field] === value));
};
console.log(filterArray(array_one, 'name', 'Stew'));
console.log(filterArray(array_two, ['id', 'company'], 2));
console.log(filterArray(array_two, ['id', 'company'], 'Company 02'));
|