Question: This days I try to create an abstract base repository using some basic CRUD functions proposed by [DapperExtensions](https://github.com/tmsmith/Dapper-Extensions). But the code given as an exemple use a SqlConnection which is made to connect to a SQL Server database. I want to be able to connect to all kind of Database (SQL Server, MySql, etc...). Also their code sample is repeated for each CRUD function as the code below show

```
using (SqlConnection cn = new SqlConnection(_connectionString))
{
    cn.Open();
    //Code doing something here...
    cn.Close();
}

```

So i was thinking about to create a **DbContext** that can handle the creation, the opening and closing of the connection and also can create the right connection object depending on the database type I want to use (a kind of **database factory**).

Is there somebody that already done it and could share his code?

Thank you guys !

Answer: 
Try this:

```
var results =
    lines
        .Aggregate(new[] { new List<string>() }.ToList(), (a, x) =>
        {
            if (x.StartsWith("Student"))
            {
                a.Add(new List<string>());
            }
            a.Last().Add(x);
            return a;
        })
        .Skip(1)
        .Select(x => new Student(x))
        .ToList();

```

From your sample data I get this:

[![result](https://i.stack.imgur.com/vPRXb.png)](https://i.stack.imgur.com/vPRXb.png)
Something like this 

```
if (args.Length < 1) return;                // optional check if any args

string text = File.ReadAllText(args[0]);

string[] parts = text.Split(new[] { "Student" }, 0);

string[][] lines = Array.ConvertAll(parts, part => part.Split(new[] { '\r', '\n' }, 1));

Debug.Print(lines[1][1]);        // "Id...: 12345"

```