chaosbot/ChaosBot/Database/Entity/BaseEntity.cs

30 lines
815 B
C#

using System;
using System.Data;
using System.Linq;
using ChaosBot.Attribute;
using ChaosBot.Database;
namespace ChaosBot.Database.Entity
{
public abstract class BaseEntity
{
protected BaseEntity() {}
public abstract void SetFromRow(DataRow row);
protected static QueryBuilder<T> Query<T>() where T : BaseEntity, new()
{
var dbEntityAttribute = typeof(T).GetCustomAttributes(
typeof(DBEntity),
true
).FirstOrDefault() as DBEntity;
if (dbEntityAttribute != null)
{
return new QueryBuilder<T>(dbEntityAttribute.Table);
}
throw new SystemException($"Class {typeof(T)} does not have an attribute of {typeof(DBEntity)} set");
}
}
}