Dreamine.Database.Core 1.0.1
Dreamine.Database.Core 데이터베이스 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DatabaseEntityMap.cs
이 파일의 문서화 페이지로 가기
1using System.Reflection;
2using System.Collections.Concurrent;
3using Dreamine.Database.Abstractions.Mapping;
4
6
15public sealed class DatabaseEntityMap
16{
25 private static readonly ConcurrentDictionary<Type, DatabaseEntityMap> Cache = new();
26
59 private DatabaseEntityMap(Type entityType, string tableName, IReadOnlyList<DatabasePropertyMap> properties)
60 {
61 EntityType = entityType;
62 TableName = tableName;
63 Properties = properties;
64 Key = properties.FirstOrDefault(x => x.IsKey);
65 InsertableProperties = properties.Where(x => !x.IsGenerated).ToArray();
66 UpdatableProperties = properties.Where(x => !x.IsGenerated && !x.IsKey).ToArray();
67 }
68
77 public Type EntityType { get; }
78
87 public string TableName { get; }
88
97 public IReadOnlyList<DatabasePropertyMap> Properties { get; }
98
107 public DatabasePropertyMap? Key { get; }
108
117 public IReadOnlyList<DatabasePropertyMap> InsertableProperties { get; }
118
127 public IReadOnlyList<DatabasePropertyMap> UpdatableProperties { get; }
128
154 {
155 return Create(typeof(T));
156 }
157
190 public static DatabaseEntityMap Create(Type entityType)
191 {
192 ArgumentNullException.ThrowIfNull(entityType);
193 return Cache.GetOrAdd(entityType, CreateUncached);
194 }
195
220 private static DatabaseEntityMap CreateUncached(Type entityType)
221 {
222 var tableName = entityType.GetCustomAttribute<DatabaseTableAttribute>()?.Name ?? entityType.Name;
223 var properties = entityType
224 .GetProperties(BindingFlags.Instance | BindingFlags.Public)
225 .Where(x => x.CanRead)
226 .Where(x => x.GetCustomAttribute<DatabaseIgnoreAttribute>() is null)
228 .ToArray();
229
230 return new DatabaseEntityMap(entityType, tableName, properties);
231 }
232}
static DatabaseEntityMap CreateUncached(Type entityType)
IReadOnlyList< DatabasePropertyMap > UpdatableProperties
DatabaseEntityMap(Type entityType, string tableName, IReadOnlyList< DatabasePropertyMap > properties)
static DatabaseEntityMap Create(Type entityType)
IReadOnlyList< DatabasePropertyMap > InsertableProperties
static readonly ConcurrentDictionary< Type, DatabaseEntityMap > Cache
IReadOnlyList< DatabasePropertyMap > Properties
static DatabasePropertyMap Create(PropertyInfo property)