[英]Alternative way to get data from database
Im working on a WCF + MVC application and I'm not using Entity Framework. 我正在使用WCF + MVC应用程序,但是我没有使用实体框架。 What I would like to do is to get data out of my "Customer" table (Which currently has like 13 "customers") and post it to a Chart in MVC.
我想做的是从“客户”表(目前有13个“客户”)中获取数据,并将其发布到MVC中的图表中。 I stumbled upon this code from Microsofts site :
我从Microsoft网站偶然发现了以下代码:
@{
var db = Database.Open("SmallBakery");
var data = db.Query("SELECT Name, Price FROM Product");
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Product Sales")
.DataBindTable(dataSource: data, xField: "Name")
.Write();
}
But I'm not using Entity Framework, and my Database is in a class library that communicates with my WCF, which is then being referenced through a ServiceReference in my MVC project. 但是我没有使用Entity Framework,并且我的数据库位于与WCF进行通信的类库中,然后通过我的MVC项目中的ServiceReference对其进行引用。
So my question is, what would correspond to var db = Database.Open("SmallBakery");
所以我的问题是,对应于
var db = Database.Open("SmallBakery");
and 和
.DataBindTable(dataSource: data, xField: "Name")
The DataSource
can be just an IEnumerable
; DataSource
可以只是IEnumerable
; as long as you specify an existing property on the xField
you should be able to view your graph. 只要您在
xField
上指定一个现有属性,您就应该能够查看图形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.