We are using NHibernate with SQL Server for our backend. I want to retrieve the list of all indexes on a few of my tables programmatically. Is there a way to do this using NHibernate or even ADO.Net?
I can query the sys tables to get this info but was wondering if there are any APIs for this.
Searching has not really returned any concrete solutions. If anyone else has done something similar, what were your findings and your final approach?
Any suggestions or pointers will be highly appreciated.
There is no API for this in either ADO.NET or NHibernate because this is a highly implementation specific construct and some platforms you might use NHibernate or ADO.NET with do not have this concept at all. ADO.NET and NHibernate are abstractions, and, as such, they are going to hide things (or not even use some features) in the interest of presenting a general interface.
If you want a .NET API to SQL Server metadata, the thing to look at would be SMO (which has a Table object with an Indexes property) – this is part of the Microsoft.SqlServer namespace (not System.Data).