<commit_before>AtleX.Data
==========

Small utility library to manage Entity Framework contexts.<commit_msg>Expanded the Readme<commit_after>AtleX.Data
==========

Small utility library to manage Entity Framework contexts.

## Usage

### Initialization

Extend the DbContextReposity class to insert your DbContext object:

```csharp
public class DummyRepository : DbContextRepository<DummyContext>
{
	public DummyRepository()
		: base(new DummyContext())
	{

	}
}
```

### Query data

Query data is done via de `Query<T>()` method which needs an entity type tracked by the context. 

```csharp
using (DbContextRepository repos = new DummyRepository())
{
	// All objects
	var allObjects = repos.Query<DummyObject>().ToList();
}
```

The `IQueryable` returned by `Query<T>()` can be used to customise the query.

```csharp
using (DbContextRepository repos = new DummyRepository())
{
	// All objects created in the last 7 dages
	var allObjects = repos.Query<DummyObject>().Where(o => o.Created >= DateTime.UtcNow.AddDays(-7)).ToList();
}
```

### Adding an object

Just use `Add<T(T objectToAdd)` to add new object

```csharp
using (DbContextRepository repos = new DummyRepository())
{
	DummyObject dummy = new DummyObject();
	repos.Add<DummyObject>(dummy);
	repos.SaveChanges(); // Don't forget to call this
}
```

### Deleting an object

Call `Delete<T(T objectToDelete)` to delete a state tracked object

```csharp
using (DbContextRepository repos = new DummyRepository())
{
	DummyObject dummy = repos.Query<DummyObject>().SingleOrDefault(o => o.Id == 1);
	repos.Delete<DummyObject>(dummy);
	repos.SaveChanges(); // Don't forget to call this
}
```

## IHasCreated & IHasLastModified

New entities that implement the `IHasCreated` have the value of their `Created` property set
when `SaveChanges()` is called. Of course it doesn't update this value on modified, as opposed 
to created, entities.

`IHasLastModified` is updated every time an entity is saved, but only if it has any of its values
changed.
{'fraction_non_alphanumeric': 0.12237762237762238, 'fraction_numerical': 0.0014985014985014985, 'mean_word_length': 5.144171779141105, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '694398', 'n_tokens_mistral': 639, 'n_tokens_neox': 589, 'n_words': 211}