Search code examples
ormkephas

Is Kephas.Data some kind of ORM?


Digging more through the Kephas Framework I noticed that Kephas.Data provides a functionality similar to that of classical ORMs. However, I did not find any kind of documentation about how to connect to databases or, at least, to clarify whether my assumption is correct or not.


Solution

  • No, Kephas.Data is an abstraction over data persistence. It can be mapped over typical ORMs, or it can be bound directly to a persistance store, like MongoDB. Here are some starting points:

    • Whenever you need access to data, import the IDataSpace service through a factory, something like the code below:
        public class DataConsumer
        {
            IExportFactory<IDataSpace> dataSpaceFactory;
    
            public DataConsumer(IExportFactory<IDataSpace> dataSpaceFactory)
            {
                this.dataSpaceFactory = dataSpaceFactory;
            }
    
            public async Task<> GetDocumentsCountAsync(CancellationToken token)
            {
                using (var dataSpace = dataSpaceFactory.CreateExportedValue())
                {
                    var documentCount = await dataSpace.Query<Document>().CountAsync().PreserveThreadContext();
                    return documentCount;
                } 
            }
        }
    
    • Use the Query<TEntity>() method to query for entities, using LINQ to shape the data. However, you have to make sure that the underlying infrastructure understands the LINQ you use.

    • Use CreateEntityAsync<TEntity>() : TEntity, DeleteEntity(entity), FindAsync<TEntity>(id): TEntity, FindOneAsync<TEntity>(linq_expression) to create, delete, or find an entity.

    • Use PersistChangesAsync() to persist the changes in memory to the persistence store.

    A DataSpace can hold multiple DataContexts, each DataContext being responsible for a dedicated data store. The discrimination is done by entity type.

    Each DataContext implementation is bound to the specific store. By default, Kephas provides the MongoDB adapter, an Entity Framework adapter being also planned.

    A special feature is the integration of DataBehaviors, which are invoked upon data or query operations.

    For more information please consult https://github.com/kephas-software/kephas/wiki/Architecture-of-data-access and the similar wiki pages.