贴部分代码
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
数据库自己新建一下