public static MetaTable GetTable (this IDynamicDataSource dataSource)
{
if (dataSource == null)
return null;
string entitySetName = dataSource.EntitySetName;
if (String.IsNullOrEmpty (entitySetName)) {
// LAMESPEC: MSDN says we should throw in this case, but .NET calls
// DynamicDataRouteHandler.GetRequestMetaTable(HttpContext
// httpContext) instead (eventually)
MetaTable ret = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
if (ret == null)
throw new InvalidOperationException ("The control '" + GetDataSourceId (dataSource) +
"' does not have a TableName property and a table name cannot be inferred from the URL.");
}
Type contextType = dataSource.ContextType;
if (contextType == null)
throw new InvalidOperationException ("The ContextType property of control '" + GetDataSourceId (dataSource) + "' must specify a data context");
return MetaModel.GetModel (contextType).GetTable (entitySetName);
}