diff --git a/DbContextExtensions.vb b/DbContextExtensions.vb index 3273ae3..737328c 100644 --- a/DbContextExtensions.vb +++ b/DbContextExtensions.vb @@ -1,8 +1,9 @@ -Imports System.Reflection +Imports System.ComponentModel.DataAnnotations +Imports System.Linq.Dynamic.Core +Imports System.Reflection Imports System.Runtime.CompilerServices Imports Microsoft.EntityFrameworkCore Imports Microsoft.EntityFrameworkCore.Internal -Imports System.Linq.Dynamic.Core Namespace Extensiones @@ -33,7 +34,21 @@ Namespace Extensiones If Tabla Is Nothing Then Throw New Exception("Tabla " & NombreTablaBase & " no encontrada") Dim Campo = Tabla.FindProperty(NombreCampo) If Campo Is Nothing Then - Return -1 ' Throw New Exception("No existe el campo " & NombreCampo & " en la tabla " & NombreTablaBase) + Dim tipo = AppDomain.CurrentDomain.GetAssemblies().SelectMany(Function(a) a.GetTypes()).FirstOrDefault(Function(t) t.FullName = EspacioNombres & "." + NombreTablaBase) + + If tipo IsNot Nothing Then + Dim propiedad = tipo.GetProperty(NombreCampo) + Dim maxLengthAttr = propiedad?.GetCustomAttribute(Of MaxLengthAttribute)() + + If maxLengthAttr IsNot Nothing Then + Dim max As Integer = maxLengthAttr.Length + Return max + Else + Return -1 + End If + Else + Return -1 + End If Else Dim LongitudCampo As Integer? = Campo.GetMaxLength() diff --git a/tsEFCore8.vbproj b/tsEFCore8.vbproj index 1fe6811..ff72b6a 100644 --- a/tsEFCore8.vbproj +++ b/tsEFCore8.vbproj @@ -11,11 +11,12 @@ net8.0 tsEFCore8 net8.0, libreria - 1.0.3 + 1.0.5 Pedro Tecnosis S.A Utilidades Entity Framework compatibles con EF Core 8. + - 1.0.5 2026-03-18 Se comprueba el atributo MaxLength en ObtieneLongitudCampo en caso de que no se encuentre la propiedad - Se agrega README.md README.md