1

Base entity interface is IEntity which requires only "object ID {get;set;}" to be implemented. Now, in almost every case ID is of Guid type (except for membership etc). I am using following code to do mapping of interface

...
    AnyPart<IEntity> primaryMap = ReferencesAny(x => x.Primary)
                    .IdentityType<object>() // tried with .IdentityType<Guid>()
                    .EntityIdentifierColumn("PrimaryID")
                    .EntityTypeColumn("PrimaryType")
                    .MetaType<string>();
...

Of course, next I am adding meta values.

So, Now getting error

Source array was not long enough. Check srcIndex and length, and the array's lower bound

And with .IdentityType<Guid>()

could not resolve property: Primary.ID of: Founder.Connection [.SingleOrDefault[Founder.Connection](NHibernate.Linq.NhQueryable`1[Founder.Connection], Quote((x, ) => (OrElse(AndAlso(Equal(x.Primary.ID, 35c2142a-4c17-4b77-96fd-a2570028a211), Equal(x.Secondary.ID, 35c2142a-4c17-4b77-96fd-a2570028a211)), AndAlso(Equal(x.Secondary.ID, 35c2142a-4c17-4b77-96fd-a2570028a211), Equal(x.Primary.ID, 35c2142a-4c17-4b77-96fd-a2570028a211))))), )]

UPDATE:

I tried also with .IdentityType(x=>x.ID) but same problem (Source array was not long enough)

UPDATE II:

Query (Actually whole method containing query) that this error occurs on is bellow:

public IQueryable<Connection> GetConnections(IEntity connectable)
        {
            IQueryable<Connection> query =
                Query().Where(
                    x => x.Primary.ID == connectable.ID || x.Secondary.ID == connectable.ID);
            return query;
        }

a faster solution for random text w/r in Python

I need a fast solution for random w/r of text snippets in Python. What I want to do is like this:

  1. Write the snippet and record a pointer
  2. Use the pointer to retrieve the snippet

The snippets are of arbitrary length and I choose not to use a database to store them, but only the pointers. By simply replacing Python file methods with C functions (solution 1), it's been pretty fast and the pointers consist of only "where" and "how long" of the snippet. After that, I experimented what I thought is the real thing that works with Berkeley DB. I don't know what to call it, a "paging" something perhaps?

The thing is, this code definitely works, 1.5 to 2 times faster than solution 1, but it isn't a lot faster and needs to use a 4-part pointer. Perhaps this is not a worthy method, but is there any room to significantly improve it?

The following is the code:

from collections import namedtuple
from ctypes import cdll,c_char_p,\
     c_void_p,c_size_t,c_long,\
     c_int,create_string_buffer
libc = cdll.msvcrt
fopen = libc.fopen
fread = libc.fread
fwrite = libc.fwrite
fseek = libc.fseek
ftell = libc.ftell
fflush = libc.fflush
fclose = libc.fclose

#######################################################
# The following is how to write a snippet into the SnippetBase file

ptr = namedtuple('pointer','blk1, start, nblk, length')
snippet = '''
blk1: the first blk where the snippet is
start: the start of this snippet
nblk: number of blocks this snippet takes
length: length of this snippet
'''
bsize = 4096 # bsize: block size

fh = fopen('.\\SnippetBase.txt','wb')
fseek(fh,0,2)
pos1 = divmod(ftell(fh),bsize)
fwrite(snippet,c_size_t(len(snippet)),1,fh)
fflush(fh)
pos2 = divmod(ftell(fh),bsize)
ptr = ptr(pos1[0],pos1[1],pos2[0]-pos1[0]+1,len(snippet))
fclose(fh)


#######################################################
# The following is how to read the snippet from the SnippetBase file

fh = fopen('.\\SnippetBase.txt','rb')
fseek(fh,c_long(ptr.blk1*bsize),1)
buff = create_string_buffer(ptr.nblk*bsize)
fread(buff,c_size_t(ptr.nblk*bsize),1,fh)
print buffer(buff,ptr.start,ptr.length)
fclose(fh)
4

1 回答 1

1

在查询中试试这个:(x.Primary == connectable不带ID)。

问题是您引用了一个object(或另一个未映射的类型,这就是您需要any映射的原因)。没有IDobject

顺便说一句,使用 HQL 将允许您通过使用关键字 id 来访问 id id,这在 Linq 中不可用(从技术上讲,它可以作为扩展方法提供,但我不知道 Linq to NH 是否足以说明它已实施)。每个any引用在概念上都有一个id和一个class

于 2013-11-14T07:42:46.910 回答