开发者

How to get the amount of colums from a SQL database with LinqDataSource?

开发者 https://www.devze.com 2023-04-13 05:34 出处:网络
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 a

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

0

精彩评论

暂无评论...
验证码 换一张
取 消