Nueva mejoras Y estabilidad

This commit is contained in:
2025-12-26 22:27:20 -06:00
parent 203859b22a
commit ac96cb1f23
23 changed files with 1841 additions and 480 deletions

63
MicroORM/OrmMetadata.cs Normal file
View File

@@ -0,0 +1,63 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
namespace MicroORM;
public class OrmMetadata
{
public static string GetTableName<T>()
{
var table = typeof(T).GetCustomAttribute<TableAttribute>();
if (table == null)
throw new InvalidOperationException("La entidad no tiene [Table]");
return string.IsNullOrEmpty(table.Schema)
? table.Name
: $"{table.Schema}.{table.Name}";
}
public static PropertyInfo GetKeyProperty<T>()
{
var key = typeof(T)
.GetProperties()
.FirstOrDefault(p => p.GetCustomAttribute<KeyAttribute>() != null);
if (key == null)
throw new InvalidOperationException("La entidad no tiene [Key]");
return key;
}
public static string GetColumnName(PropertyInfo prop)
{
var columnAttr = prop.GetCustomAttribute<ColumnAttribute>();
return columnAttr?.Name ?? prop.Name;
}
public static bool IsIdentity(PropertyInfo prop)
{
var key = prop.GetCustomAttribute<KeyAttribute>() != null;
var dbGenerated = prop.GetCustomAttribute<DatabaseGeneratedAttribute>();
return key &&
dbGenerated?.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity;
}
public static IEnumerable<PropertyInfo> GetScaffoldProperties<T>()
{
var type = typeof(T);
var key = GetKeyProperty<T>();
return type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p =>
p.CanWrite && // tiene setter
p.GetCustomAttribute<NotMappedAttribute>() == null &&
(
p.GetCustomAttribute<ColumnAttribute>() != null ||
p == key
)
);
}
}