È possibile farlo tramite riflessione. In sostanza, si esegue l'iterazione sulle proprietà nella classe DataContext. Per ogni proprietà, verificare se il tipo di parametro generico di quella proprietà ha l'attributo TableAttribute. In tal caso, quella proprietà rappresenta una tabella:
using System.Reflection;
using System.Data.Linq.Mappings;
PropertyInfo[] properties = typeof(MyDataContext).GetProperties();
foreach (PropertyInfo property in properties)
{
if(property.PropertyType.IsGenericType)
{
object[] attribs = property.PropertyType.GetGenericArguments()[0].GetCustomAttributes(typeof(TableAttribute), false);
if(attribs.Length > 0)
{
Console.WriteLine(property.Name);
}
}
}
fonte
2009-04-09 23:04:42
Bello, non lo sapevo. –
whooo hoo è ancora meglio! – Sergey
Sì, continuo a cercare cose del genere da solo. È sempre divertente passarne uno :). –