使用Web服务获取数据 [英] Fetching data using web service

查看:66
本文介绍了使用Web服务获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web服务使用实体框架工作和存储过程从数据库中获取数据。

是否必须将此数据与模型绑定?

I am using web service to fetch data from database using entity frame work and stored procedure.
Is it compulsory to bind this data with the model?

推荐答案

如果你正在使用Entity框架,你可能会查看(无论是HTML网页还是Web表单)已经绑定到你的模型......实体框架使用模型来获取数据或执行不同的CRUD操作。你正在看的名单;在查询数据库之后是实体框架对模型的C R UD操作的结果。



如果您要为所有操作使用Entity框架,创建,读取,更新和删除,那么您的模型将绑定到您的应用程序的视图用于操作。由您来决定模型绑定。顺便说一下,编程中没有必修。这只是编程模型的要求; 范例的。所以,你正在使用哪种模式,阅读它,你会在那里更明确地找到它的答案。
Chances are that if you're using Entity framework, you view (what ever it is, HTML web page or a Web Form) is already bound to your model... Entity framework uses a model to fetch data or to perform different CRUD operations. The list that you're watching; after querying the database is a result of the CRUD operation of Entity framework over model.

If you're going to use Entity framework for all of your operations, create, read, update and delete, then yes your model will be bound to your application's views for operations. It is up to you, how you define "model binding". By the way, there is nothing compulsory in programming. It is just a requirement of your programming model; paradigm. So, which so ever pattern you're using, read about it and you will find the answer about it more explicitly there.


[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string GetSubCategories(int CategoryId)
        {

            DataTable dt = BusinessLayer.ycfoCore.populateSubCategories(CategoryId.ToString());

            var query = from row in dt.AsEnumerable()
                        select new
                        {
                            Id = row["Id"].ToString(),
                            Name = (string)row["Name"]
                        };

            JObject o = JObject.FromObject(new
            {
                Table = query
            });

            return o.ToString();
        }


这篇关于使用Web服务获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆