-
Notifications
You must be signed in to change notification settings - Fork 40
/
EntitiesBuilder.cs
38 lines (33 loc) · 1.2 KB
/
EntitiesBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Mondol. All rights reserved.
//
// Author: frank
// Email: [email protected]
// Created: 2017-01-22
//
using System;
using System.Collections.Generic;
using System.Linq;
using Mondol.DapperPoco.Metadata;
namespace Mondol.DapperPoco
{
public class EntitiesBuilder
{
private readonly Dictionary<Type, IEntityBuilder> _entityTypeBuilders = new Dictionary<Type, IEntityBuilder>();
public virtual EntityBuilder<TEntity> Entity<TEntity>() where TEntity : class
{
var eType = typeof(TEntity);
if (_entityTypeBuilders.ContainsKey(eType))
throw new InvalidOperationException($"Entity {eType.FullName} already exists");
var etBuilder = new EntityBuilder<TEntity>();
_entityTypeBuilders.Add(eType, etBuilder);
return etBuilder;
}
internal Entities Build()
{
var entityTypes = _entityTypeBuilders
.Select(p => new KeyValuePair<Type, FluentEntityTableInfo>(p.Key, p.Value.Build()))
.ToDictionary(p => p.Key.TypeHandle, p => p.Value);
return new Entities(entityTypes);
}
}
}