any

Linq To Entities - Any VS First VS Exists

不打扰是莪最后的温柔 提交于 2019-12-01 03:08:42
I am using Entity Framework and I need to check if a product with name = "xyz" exists ... I think I can use Any(), Exists() or First(). Which one is the best option for this kind of situation? Which one has the best performance? Thank You, Miguel Any translates into "Exists" at the database level. First translates into Select Top 1 ... Between these, Exists will out perform First because the actual object doesn't need to be fetched, only a Boolean result value. At least you didn't ask about .Where(x => x.Count() > 0) which requires the entire match set to be evaluated and iterated over before

Python, Press Any Key To Exit

只愿长相守 提交于 2019-11-30 13:47:29
问题 So, as the title says, I want a proper code to close my python script. So far, I've used input('Press Any Key To Exit') , but what that does, is generate a error. I would like a code that just closes your script without using a error. Does anyone have a idea? Google gives me the input option, but I don't want that It closes using this error: Traceback (most recent call last): File "C:/Python27/test", line 1, in <module> input('Press Any Key To Exit') File "<string>", line 0 ^ SyntaxError:

Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 12:58:01
问题 I have this code (the whole code is not important but can be seen on this link): internal static class PlayCardActionValidator { public static bool CanPlayCard(...) { // ... var hasBigger = playerCards.Any( c => c.Suit == otherPlayerCard.Suit && c.GetValue() > otherPlayerCard.GetValue()); // ... } } After opening the code in decompiler (ILSpy) for example I noticed the existence of newly created class <>c__DisplayClass0_0 by the C# compiler: This wouldn't be a problem for me if this code wasn

SQLAlchemy filter query “column LIKE ANY (array)”

纵然是瞬间 提交于 2019-11-30 12:20:24
Hi SQLAlchemy experts out there, here's a tricky one for you: I'm trying to write a query that resolves into something like: SELECT * FROM MyTable where my_column LIKE ANY (array['a%', 'b%']) using SQLAlchemy: foo = ['a%', 'b%'] # this works, but is dirty and silly DBSession().query(MyTable).filter("my_column LIKE ANY (array[" + ", ".join(["'" + f + "'" for f in token.tree_filters]) + "])") # something like this should work (according to documentation), but doesn't (throws "AttributeError: Neither 'AnnotatedColumn' object nor 'Comparator' object has an attribute 'any'" DBSession().query

Python, Press Any Key To Exit

牧云@^-^@ 提交于 2019-11-30 08:32:24
So, as the title says, I want a proper code to close my python script. So far, I've used input('Press Any Key To Exit') , but what that does, is generate a error. I would like a code that just closes your script without using a error. Does anyone have a idea? Google gives me the input option, but I don't want that It closes using this error: Traceback (most recent call last): File "C:/Python27/test", line 1, in <module> input('Press Any Key To Exit') File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing Have you tried raw_input() ? It could be that you are getting a syntax error

any() function in Python with a callback

点点圈 提交于 2019-11-30 06:19:02
问题 The Python standard library defines an any() function that Return True if any element of the iterable is true. If the iterable is empty, return False. It checks only if the elements evaluate to True . What I want it to be able so specify a callback to tell if an element fits the bill like: any([1, 2, 'joe'], lambda e: isinstance(e, int) and e > 0) 回答1: How about: >>> any(isinstance(e, int) and e > 0 for e in [1,2,'joe']) True It also works with all() of course: >>> all(isinstance(e, int) and

Swift专题讲解十九——类型转换

 ̄綄美尐妖づ 提交于 2019-11-29 16:51:13
Swift专题讲解十九——类型转换 一、类型检查与转换 在Objective-C和Java中,任何类型实例都可以通过强转使编译器认为它是另一种类型的实例,这么做其实是将所有的安全检查工作都交给了开发者自己来做。先比之下,Swift中的Optional类型转换就会比较安全与可靠。 Swift中使用is关键字来进行类型的检查,其会返回一个布尔值true或者false来表明检查是否成立,示例如下: var str = "HS" if str is String { print(str) } Swift中有向上兼容与向下转换的特性,就是说,一个父类类型的集合可以接收子类的实例,同样,在使用这些实例变量时可以将其向下转换为子类类型,示例如下: //自定义一个类及其子类 class MyClass { var name:String? } class MySubClassOne: MyClass { var count:Int? } class MySubClassTwo: MyClass { var isBiger:Bool? } //创建3个实例 var obj1 = MyClass() obj1.name = "HS" var obj2 = MySubClassOne() obj2.count = 100 var obj3 = MySubClassTwo() obj3.isBiger

postgreSQL - in vs any

旧城冷巷雨未停 提交于 2019-11-28 20:23:09
I have tried both 1) smthng = any (select id from exmplTable) 2) smthng in (select id from exmplTable) and I am getting the same results for my data. Is there any difference for the two expresions ? No, in these variants are same: You can see - the execution plans are same too: postgres=# explain select * from foo1 where id in (select id from foo2); ┌──────────────────────────────────────────────────────────────────┐ │ QUERY PLAN │ ╞══════════════════════════════════════════════════════════════════╡ │ Hash Semi Join (cost=3.25..21.99 rows=100 width=4) │ │ Hash Cond: (foo1.id = foo2.id) │ │ ->

any() function in Python with a callback

心已入冬 提交于 2019-11-28 17:09:38
The Python standard library defines an any() function that Return True if any element of the iterable is true. If the iterable is empty, return False. It checks only if the elements evaluate to True . What I want it to be able so specify a callback to tell if an element fits the bill like: any([1, 2, 'joe'], lambda e: isinstance(e, int) and e > 0) How about: >>> any(isinstance(e, int) and e > 0 for e in [1,2,'joe']) True It also works with all() of course: >>> all(isinstance(e, int) and e > 0 for e in [1,2,'joe']) False any function returns True when any condition is True. >>> any(isinstance(e

Relationships in Doctrine

吃可爱长大的小学妹 提交于 2019-11-28 14:50:28
I have 2 Entities: Categories and products. How can I build a relationship between these Entities? Category Entity: class Category { private $id; private $name; private $parent; public function getChildren() { return $this->children; } //setters and getters } Items Entity: class Items { private $id; private $name; private $price; private $color; private $size; private $weight; //getters and setters } Category yml: AppBundle\Entity\Category: type: entity oneToMany: children: targetEntity: AppBundle\Entity\Category mappedBy: parent orderBy: name: ASC manyToOne: parent: targetEntity: AppBundle