CSharp · Console
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
using System.Linq;
[Table("Login", Schema = "dbo")]
public class Login
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[MaxLength(50)]
public string UserName { get; set; }
[Required]
[MaxLength(150)]
public string Email { get; set; }
}
public class Program
{
public static void Main()
{
TableAttribute tableAttribute1 = (TableAttribute)typeof(Login).GetCustomAttributes(typeof(TableAttribute)).FirstOrDefault();
Console.WriteLine("{0}", tableAttribute1.Schema);
Login lg = new Login();
TableAttribute tableAttribute2 = (TableAttribute)lg.GetType().GetCustomAttributes(typeof(TableAttribute)).FirstOrDefault();
Console.WriteLine("{0}", tableAttribute1.Schema);
}
}