there exists a nice database called LiteDB. What I find inconvenient is an absence of attributes for specifying the relation type (value/reference) between entities, though LiteDB provides fluent interface for hardcoding it (details: https://github.com/mbdavid/LiteDB/wiki/DbRef). I am lazy guy and don't want always update this hardcoded relations to follow the changes in my data model. So I decided to realize the runtime discovery of the data model entities with the properties attributed by DbRef (my custom attribute). Unfortunately, I am stuck a little with creating the
Expression<Func<T,K>>
in the .Net runtime... for providing it in the following call (first parameter):
BsonMapper.Global.Entity<Order>().DbRef(x => x.Customer, "customers");
Types T and K are given in runtime as instances of System.Type (here in example: T - Order, K - Customer).
I'll really appreciate if you guys give me some hints on how to instantiate
Expression<Func<T,K>>
in .Net runtime in order to provide it to ...DbRef(...) function.
Well, you have the entity type
T
, property typeK
and the property name. To build theExpression<Func<T, K>>
you could simply useExpression.Parameter
,Expression.Property
andExpression.Lambda
methods like this:From you question. Let me send a screenshot to you maybe it can give you a clueExpression> Example
I hope this will help