Get an array of table columns in LINQ To SQL

How to get an array of data columns via LINQ to SQL? I am looking for something like this:

DataColumn[] dc = DataContext.Table.Columns;  
+3
source share
2 answers

Try:

var dataColumns =
    from member in yourDataContext.Mapping.GetMetaType(typeof(YourMappedType)).DataMembers
    select new DataColumn {
        ColumnName = member.MappedName,
        DataType = (
            member.Type.IsGenericType && member.Type.GetGenericTypeDefinition() == typeof(Nullable<>)
                ? new NullableConverter(member.Type).UnderlyingType
                : member.Type
        ),
        AllowDBNull = member.CanBeNull
    };
+3
source
myDataContext.Mapping.GetTable (typeof (Customer)).RowType.DataMembers
+3
source

Source: https://habr.com/ru/post/1771139/


All Articles