sequences

Sequence contains no elements when using count on LINQ Query

妖精的绣舞 提交于 2019-12-11 20:50:44
问题 IEnumerable<EntityReference> children = ( from c in OrgContext.CreateQuery<Account>() where c.ParentAccountId != null && c.ParentAccountId.Id.Equals(parentGuid) select c.ToEntityReference()).ToList(); return children.Count() > 0 ? null : new List<EntityReference>(); Throws a "Sequence contains no elements" error. How can I reliably check if the sequence is empty before trying to count the elements? (I'd expect Count to simply return 0) 回答1: This error for me was caused by visual studio using

translate my sequence?

微笑、不失礼 提交于 2019-12-11 13:16:52
问题 I have to write a script to translate this sequence: dict = {"TTT":"F|Phe","TTC":"F|Phe","TTA":"L|Leu","TTG":"L|Leu","TCT":"S|Ser","TCC":"S|Ser", "TCA":"S|Ser","TCG":"S|Ser", "TAT":"Y|Tyr","TAC":"Y|Tyr","TAA":"*|Stp","TAG":"*|Stp", "TGT":"C|Cys","TGC":"C|Cys","TGA":"*|Stp","TGG":"W|Trp", "CTT":"L|Leu","CTC":"L|Leu", "CTA":"L|Leu","CTG":"L|Leu","CCT":"P|Pro","CCC":"P|Pro","CCA":"P|Pro","CCG":"P|Pro", "CAT":"H|His","CAC":"H|His","CAA":"Q|Gln","CAG":"Q|Gln","CGT":"R|Arg","CGC":"R|Arg", "CGA":"R

Hibernate and Postgresql - generator class in hibernate mapping file

我怕爱的太早我们不能终老 提交于 2019-12-11 07:29:49
问题 The ids in my postgresql database are auto-incremental (there are sequences defined in a database). When creating a hibernate mapping files I set the class generator to increment: <class name="model.Names" schema="public" table="names"> <id name="id" type="int"> <column name="id"/> <generator class="increment"/> </id> However, I keep getting all kinds of errors (null pointer exceptions, org.hibernate.TransactionException: Transaction not successfully started) so I first wanted to make sure

nhibernate alternate id's using generated properties

懵懂的女人 提交于 2019-12-11 07:29:11
问题 ** This question has been edited to make it simpler and more focused ** Employee has an EmployeeNumberValue property which I would like to have auto-incremented by the db. To the business domain, this is a unique id assigned to employees and used to identify them on employee cards, etc. To the database however, it is an alternate id and not the primary key. NHib has a documented ability called Generated Properties. Per the docs, "generated properties are properties which have their values

Implementing __concat__ in Python

蓝咒 提交于 2019-12-11 07:05:26
问题 I tried to implement __concat__ , but it didn't work >>> class lHolder(): ... def __init__(self,l): ... self.l=l ... def __concat__(self, l2): ... return self.l+l2 ... def __iter__(self): ... return self.l.__iter__() ... >>> lHolder([1])+[2] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'lHolder' and 'list' How can I fix this? 回答1: __concat__ is not a special method (http://docs.python.org/glossary.html#term-special-method

How to specify list of values for a postgresql sequence

寵の児 提交于 2019-12-11 06:22:38
问题 I have a list of integer values X and I want a primary key for my table Y to come from that list of integer values. I was wondering if this could be done using sequences. In other words: is there a way to tell a PostgreSQL sequence to use this list X to generate primary keys for my table Y ? One way of doing this would be to use a sequence that contains the index of the last used integer from the list X , call setval() on the sequence, get the next value and try to insert it into my table Y .

counts sequences in R

左心房为你撑大大i 提交于 2019-12-11 03:05:21
问题 id random count a 0 -1 a 1 1 a 1 2 a 0 -1 a 0 -2 a 1 1 a 0 -1 a 1 1 a 0 -1 b 0 -1 b 0 -2 b 1 1 b 0 -1 b 1 1 b 0 -1 b 0 -2 b 0 -3 id is a player , random is binary 0 or 1 , I want to create a count column that counts the sequences of 1's and 0's by player , preferably without loops since the database is very big. 回答1: Here's a dplyr solution dat %>% transform(idx = c(0,cumsum(random[-1L] != random[-length(random)]))) %>% group_by(id, idx) %>% mutate(count = -1*cumsum(random == 0) + cumsum

Retrieving next available AutoNumber

那年仲夏 提交于 2019-12-11 02:49:02
问题 I am busy with a school project where I query a database based on a server from a client. One of the requirements is to retrieve the next available AutoNumber from the database. What would the SQL query be to retrieve the next available Autonumber ? Is it possible to do this? 回答1: It depends on the flavor of the RDBMS. MariaDB (MySQL) have LAST_INSERT_ID() function which gives you the last value of an AUTO_INCREMENT field. Databases that support sequences (say Ingres) allow you to get next

Readable unit testing of a yielded sequence?

半腔热情 提交于 2019-12-11 02:17:14
问题 Let's suppose I have some method that returns a IEnumerable<int> object. This methods make use of yield return keyword to produce a infinite sequence. Example of the Fibonacci algorithm : public static IEnumerable<long> Fibonacci() { long x = 0L; long y = 1L; long z; yield return x; yield return y; while (true) { z = x + y; yield return z; y = x; x = z; } } How can I properly create unit test for such sequence ? By proper I also mean readable. I can write unit tests like this : [TestMethod]

Creating unique groups in sequential data that repeats through time

那年仲夏 提交于 2019-12-11 02:16:48
问题 This kind of thing has been asked before, but not quite in this way that I can find. Thread about creating sequential IDs, with several additional links It's not hard to create identifiers in a sequence, but my data includes a temporal element that has thrown me for a loop. The following data is an imaginary dataset just to illustrate the problem in something tractable: dput(walking_dat) structure(list(neighborhood = structure(c(3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L), .Label = c(