FAQ
Q. How to get parent object?
Supposedly we have:
class
Account
{
List<Phone> Phones;
List<Contact> Contacts;
//...
}
class
Contact
{
List<Phone> Phones;
//...
}
class
Phone
{
//some properties;
}
First, we query for a full list of Phone and display the result in
a UI list. Next, once a user choose a particular Phone from UI, we
need to retrieve its parent object (could be of type either Account
of Contact, of course).
What's the best way to achieve this?
A. Assume that phone is
object from the database and being selected by user
SELECT Account WHERE Phones._items
CONTAINS phone
or
SELECT Account WHERE Phones._items.number
== 123456789
Where _items is an array inside
List<T>. All such properties can be discovered with
use of Reflector.
Q. Just wanted to check that I will not have an issue
with multi-threaded concurrent access the Embedded DB. All threads will
be using the same connection.
A. Having a separate class with the public thread-safe method like
Store-* or Delete-* with locking on the database operations looks like the
safest solution, although not the most performing.
Please note that queries are lazy-evaluated, and running LINQ or
SQL queries does not guarantee that the result set is on the client side. Because
of this, you cannot query the database from different threads and getting the
result set at the same time. If you need an immediate execution of queries,
convert result sets into arrays of objects by calling .ToArray() method for IEnumerable. You might need the same locking approach for
queries as for Store and Delete.
Querying the object returned by db.Query<T>() should provide some level of isolation as LINQ and
SQL queries in the Eloquera DB cannot change data.
The same reasoning on locking applies to such queries.
Q. I'm trying to store a class with a Tuple property and
it looks like the properties of the tuple lose their values when fetching them
back from DB.
A. Update. The Tuple objects now can be
restored correctly starting with the version 3.1. The information below is
retained for your convenience only:
It seems Tuple has all properties marked as read-only
public class Tuple<T1, T2, T3> : IStructuralEquatable,
IStructuralComparable, IComparable, ITuple
{
// Fields
private readonly
T1 m_Item1;
private readonly
T2 m_Item2;
private readonly
T3 m_Item3;
Database saves the object, but object cannot be restored since
fields are marked as "readonly".
One of the solutions is to create own tuple or
remember objects that make this tuple e.g. T1, T2... and save these objects.
Then use these objects to create tuple in runtime
Q. I
installed the Server on a local pc with Win 7 Ultimate -32 bit and want to
connect to it.
I get the error "The server has rejected the client credentials."
Connection string
DB db = new DB("server=localhost;user=Admin;password=;options=none;");
Here is the section of the server config file. I
played around with
AlllowGroups and AllowUsers
- no success.
<Server ServerPort="43962"
Trace="true"
InMemoryAllowed="true"
Secure="true"
AllowUsers=""
AllowGroups="Gäste;System;HomeUser;Everyone;Administrators;Administrator;Users;Guests;Administratoren;Benutzer;Jeder;"
/>
A. For the
performance reasons, it is better to use Windows authentication using the
current user account. For this, use the following connection string:
server=localhost;password=;options=none;
For
debugging, remove all group names from the configuration file, and leave only
Everyone (the group name may be different in the German version of Windows). Do
not forget to restart the Eloquera DB Server service.
Q. Can Eloquera store objects
of Hashtable type?
A. Eloquera Database can store any .NET objects,
in general.
Although there are some types
that are not stored. Those are
pointer types (all types like byte* or IntPtr - they
make no sense being restored later on), and instances of Type class (they
cannot exist by themselves, they must be derived either by using typeof()
operator or calling GetType() method on the
instance).
But even if the class contains fields and
properties of abovementioned types, it still can be stored in Eloquera DB on its own.
Q. I'm
not sure if there already exist a method of authenticating with the DB server via
a named user authentication rather than utilizing windows authentication, but
it sure would be nice for a number of reasons.
In other words a username and password that I make up, not a domain user:
Eloquera.config named user section example:
<NamedUser
username="sa"
password="saPassword"
access="read,write"
database="FinancialDB, RetailersDB,
DistribDB" />
<NamedUser
username="jondoe"
password="jane"
access="read"
database="FinancialDB, RetailersDB,
DistribDB" />
A. That's a good
suggestion; we will consider it for one of our next releases.
Currently, you can use Windows authentication without a set up
domain, although it is not recommended because of poor connection performance.
To enable it anyway, you need to turn off a simple sharing option and enable
user and password authentication (if you are using a homegroup).
Q. I have exception with LINQ query
System.InvalidOperationException was unhandled by user code
Message=The operands for operator 'Equal' do not match
the parameters of method 'op_Equality'.
Source=System.Core
StackTrace:
at
System.Linq.Expressions.Expression.GetMethodBasedBinaryOperator(ExpressionType binaryType, Expression left, Expression right, MethodInfo method, Boolean liftToNull)
at System.Linq.Expressions.Expression.Equal(Expression
left, Expression right, Boolean liftToNull, MethodInfo method)
Here is the query
from
Dynamic d in db where d["ID"] == g select d
A. This is rather a LINQ feature. Cast
doesn’t attempt to take any implicit cast operators (the LINQ Cast code is
heavily optimized for special cases of all kinds, but nothing in that
direction) into account. Use explicit cast in such cases.
from
Dynamic d in db where (Guid)d["ID"]
== g select d
Q.
Is there a way to update an object in a
disconnected scenario, like ajax
or web services? In these scenarios the objects data will be coming in as json or xml, or some proprietary format, then deserialized into an object.
A.
Starting
from the version 3.0, the Eloquera DB supports
Dynamic objects, which hold their state between database sessions. It means
that the database can be closed after a Dynamic object is retrieved from the
database, and opened again when we need to update the same Dynamic object
without re-querying it. The same ‘disconnected’ technique applies to the native
objects with a field with an [ID] attribute (starting from the version 3.1).
The native objects without an [ID] field can still be
updated in the disconnected scenarios if their UID is known (by calling DB.GetID()
method). The update is done by calling DB.Store(uid, obj)
method.
The old approach to updating objects in the database is
still working as well: object to be updated shall be retrieved from the
database using their UID. Then required fields in the retrieved object shall be
updated and the object can be stored back. This is the safest approach as it
avoids any unintentional modification of objects’ UIDs.