zoukankan      html  css  js  c++  java
  • WCF使用LINQ连接数据库,MVC展示使用jQuery调用WCF

    贴部分代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using ORM;
    using System.ServiceModel.Activation;
    
    namespace WcfService
    {
        // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“CategoryService”。
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
        public class CategoryService : ICategoryService
        {
            private static DataClassesDataContext db = new DataClassesDataContext();
            /// <summary>
            /// 增加
            /// </summary>
            /// <param name="name"></param>
            public void Insert(string name)
            {
                Category category1 = new Category()
                {
                    Name = name
                };
                db.Category.InsertOnSubmit(category1);
                db.SubmitChanges();
            }
    
            /// <summary>
            /// 删除
            /// </summary>
            /// <param name="id"></param>
            public void Delete(int id)
            {
                db.Category.DeleteOnSubmit(db.Category.Single(c => c.ID == id));
                db.SubmitChanges();
            }
            /// <summary>
            /// 修改
            /// </summary>
            /// <param name="name"></param>
            public void Update(int id,string name)
            {
                Category category1 = db.Category.Single(c => c.ID == id);
                category1.Name = name;
                db.SubmitChanges();
            }
    
            /// <summary>
            /// 查询所有
            /// </summary>
            /// <returns></returns>
            public List<Category> GetAll()
            {
                return db.Category.ToList<Category>();
            }
            /// <summary>
            /// 根据ID进行查询
            /// </summary>
            /// <param name="id"></param>
            /// <returns></returns>
            public Category GetById(int id)
            {
                Category category1 = db.Category.Single(c => c.ID == id);
                return category1;
            }
    
            /// <summary>
            /// 根据Name模糊查询
            /// </summary>
            /// <param name="name"></param>
            /// <returns></returns>
            public List<Category> GetDataLike(string name)
            {
                var querys = from u in db.Category
                             where u.Name.Contains(name)
                             select u;
                return querys.ToList<Category>();
            }
        }
    }

    看附件吧http://download.csdn.net/detail/lishouxiangjs/5326429

    数据库自己新建一下

  • 相关阅读:
    测试
    python+selenium
    selenium使用execute_script方法执行JavaScript
    Selenium之动作链(ActionChains)
    angular组件数据
    angular
    数据库sql查询习题
    django
    集合框架Collection
    sql语句中select、 from、 where、 group by 、having、 order by的执行顺序分析
  • 原文地址:https://www.cnblogs.com/lishouxiangjs/p/3056636.html
Copyright © 2011-2022 走看看