我的数据库表'表1'列有列#1;列1','列2','列3'。
我可以使用基本实体框架代码获得IEnumerable<Table1>
。
但是,我希望发送到应用层的数据采用以下格式..
var data = [[ 'Column1', 'Column2', 'Column3'],
[Column1-Row1-Value,Column2-Row1-Value, Column3-Row1-Value],
[Column1-Row2-Value,Column2-Row2-Value, Column3-Row2-Value],
[Column1-Row3-Value,Column2-Row3-Value, Column3-Row3-Value]]
真心感谢任何帮助。
由于
答案 0 :(得分:0)
这样做的简单方法就是编写一个接收public void Example()
{
var myEfModel = GetEFData();
object[][] result = ConvertToArrayFormat(myEfModel, row => new object[] {row.Column1, row.Column2, row.Column3}, new object[] {"Column1", "Column2", "Column3"});
}
public object[][] ConvertToArrayFormat<T>(IEnumerable<T> dataSource, Func<T, object[]> rowSelector, object[] header = null)
{
var result = new List<object[]>();
if(header != null)
result.Add(header);
foreach (var item in dataSource)
{
var row = rowSelector(item);
result.Add(row);
}
return result.ToArray();
}
并输出所需数据的函数。
py27: commands succeeded
ERROR: py34: commands failed
doc: commands succeeded
[master] $ nosetests
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
...................................................
-----------------------------------------------------------------------------
898 tests run in 1.692 seconds (898 tests passed)
[master] $ python --version
Python 3.4.3