namespace LinqToSqlDemo.Test
{
class Program
{
// 数据连接文本
private static DataClasses1DataContext dataContext = new DataClasses1DataContext(); private static void Output()
{
//输出分类信息
foreach (Category c in dataContext.Category)
{
Console.WriteLine("分类" + c.ID + ":" + c.Name);
} }
static void Main(string[] args)
{
Console.WriteLine("展示列表");
Console.WriteLine();
Output(); Console.WriteLine("测试插入----请输入分类名称");
string name=Console.ReadLine();
Category cat = new Category();
cat.Name = name;
dataContext.Category.InsertOnSubmit(cat);
dataContext.SubmitChanges();
Console.WriteLine("显示列表");
Output(); Console.WriteLine("测试修改----请输入分类名称");
name = Console.ReadLine();
cat= dataContext.Category.First(c=>c.Name==name);
cat.Name = "我是update cat";
dataContext.SubmitChanges();
Console.WriteLine("显示列表");
Output(); Console.WriteLine("测试删除----请输入分类名称");
name = Console.ReadLine();
Category catDel = dataContext.Category.First(c => c.Name == name);
dataContext.Category.DeleteOnSubmit(catDel);
dataContext.SubmitChanges();
Console.WriteLine("显示列表");
Output(); Console.ReadLine();
}
}
}