How to get the amount of colums from a SQL database with LinqDataSource?
I want to make a foreach loop which runs for each column I have in my current table.
My situation is that I have my ASP.Net project where I have one Microsoft SQL Model which I imported and created an entity model with.
Within that model I have one table with 10 "columns".
I "connected" that model with a LinqDataSource object.
My question is now, how can I access that DataTable through that LinqDataSource to get the amount of columns back?
public LinqDataSource MitarbeiterDataSource = new LinqDataSource();
MitarbeiterDataSource.ID = "Mitarbei开发者_JAVA百科terDataSource";
MitarbeiterDataSource.ContextTypeName = "MitarbeiterlisteEntities";
MitarbeiterDataSource.TableName = "Mitarbeiterliste";
Thanks in advance!
var columnNames = db.ColumnNames<Orders>().Where(n => n.Member.GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), false).FirstOrDefault() != null).Select(n => n.Name);
Get the column names with the above code. Then find the count of columnNames and youve got what you want :)
Let me know if this helps
精彩评论