精华内容
下载资源
问答
  • LinQToSQL

    2009-09-08 12:16:00
    /// /// 查询 /// /// public static void LinQToSQL() { var db = new DataClasses1DataContext(); var results = from c in db.Users 

      /// <summary>
            /// 查询
            /// </summary>
            /// <param name="name"></param>
            public static void LinQToSQL()
            {
                var db = new DataClasses1DataContext();
                var results = from c in db.Users
                              where c.LoginId == "xiaoxin"
                              where c.LoginPwd=="123"
                              select c;
                foreach (var item in results)
                {
                    Console.WriteLine(item.Name+","+item.Mail);
                }
                Console.ReadKey();
            }
            /// <summary>
            /// 数据增加
            /// </summary>
            public static void LinQTOSQL2()
            {
                var db = new DataClasses1DataContext();
                int count = db.Users.Where(c => c.LoginId == "xx").Count();
                var user = new Users()
                {
                    LoginId="xx",
                    LoginPwd="123",
                    Mail="xxxx",
                    Name="xx",
                    Phone="33333333333",
                    UserRoleId=2,
                    UserStateId=1,
                    Address="zxc",
                    Gender=1
                };
                db.Users.InsertOnSubmit(user);
                db.SubmitChanges();
                int count2 = db.Users.Where(c => c.LoginId == "xx").Count();
                if (count<count2)
                {
                    Console.WriteLine("see");
                }
               
            }
            /// <summary>
            /// 多表连接查询
            /// </summary>
            public static void LinQTOSQL4()
            {

                var db = new DataClasses1DataContext();
                var resultes = from c in db.Users
                               from x in db.UserStates
                               where c.UserStateId == x.Id
                               where c.LoginId == "xiaoxin"
                               select new {c.LoginId,x.Name };
                foreach (var item in resultes)
                {
                    Console.WriteLine(item.LoginId+"~~~~~~~~~~~~"+item.Name);
                }
                Console.ReadKey();
            }
            /// <summary>
            /// 模糊查询
            /// </summary>
            public static void LinQTOSQL5()
            {
                var db = new DataClasses1DataContext();
                var resltes = from c in db.Users
                              where c.LoginId.StartsWith("x")
                              select c;
                foreach (var item in resltes)
                {
                    Console.WriteLine(item.LoginId+"--------------"+item.Name);
                }
                Console.ReadKey();
            }
            /// <summary>
            /// 删除
            /// </summary>
            public static void LinQTOSQL6()
            {
                var db = new DataClasses1DataContext();
                var reslues = (from c in db.Users
                               where c.LoginId == "xx"
                               select c).FirstOrDefault();
                db.Users.DeleteOnSubmit(reslues);
                db.SubmitChanges();
                Console.WriteLine("cg");
                Console.ReadKey();
            }
            /// <summary>
            /// 修改
            /// </summary>
            public static void LinQToSQL7()
            {
                var db = new DataClasses1DataContext();
                var reslues = (from c in db.Users
                               where c.LoginId == "xx"
                               select c).SingleOrDefault();
                reslues.Name = "xxxx";
                db.SubmitChanges();
                Console.WriteLine("ok");
                Console.ReadKey();
                          
            }

    展开全文
  • LinqToSql初探

    2019-09-29 02:03:41
    LINQ TO SQL是一种轻量级的ORM框架,它对ADO.NET进行了轻量级的封装,讲数据库原封不动的映射成模型,常用于中小型项目,优点:简单。缺点:数据库模型过于复杂时,可能不满足开发要求。 LINQ语句: ...

    LINQ TO SQL是一种轻量级的ORM框架,它对ADO.NET进行了轻量级的封装,讲数据库原封不动的映射成模型,常用于中小型项目,优点:简单。缺点:数据库模型过于复杂时,可能不满足开发要求。

     

    LINQ语句:

    简单类型查询(string):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace LINQ
    {
        class Program
        {
            public  delegate int[] generateLotsOfNumbers(int count);//产生大量随机数
            static void Main(string[] args)
            {
    
                string[] names ={"Alonso","Zheng","Smith","Jones","Smythe","Small","Ruiz","Hsieh","Jorgenson",
                                   "Ilyich","Singh","Samba","Fatimah"};
                var queryResult1 = from n in names select n;//遍历操作
                var queryResult2 = names;//lambda表达式,功能同1
                var queryResult3 = from n in names where n.StartsWith("S") select n;//查询以S开头
                var queryResult4 = names.Where(n => n.StartsWith("S"));// lambda表达式,功能同3
                var queryResult5 = from n in names where n.StartsWith("S") orderby n select n;//升序
                var queryResult6 = from n in names where n.StartsWith("S") orderby n descending select n;//降序
                var queryResult7 = names.OrderBy(n => n).Where(n => n.StartsWith("S"));//lambda表达式,功能同4
                var queryResult8 = names.OrderByDescending(n => n).Where(n => n.StartsWith("S"));//功能同5
    
                //查询大型数据集
                generateLotsOfNumbers ge = delegate(int count) //匿名函数
                {
                    Random generator = new Random(0);
                    int[] result = new int[count];
                    for(int i=0;i<count;i++)
                    {
                        result[i] = generator.Next();
                    }
                    return result;
                };
                int[] numbers = ge(12345678);
                var queryResult9 = from n in numbers where n < 1000 select n;//条件查找
                var queryResult10 = numbers.Where(n => n < 1000);//lambda表达式,功能同9
    
                //聚合运算符
                Console.WriteLine(queryResult9.Count());//数量
                Console.WriteLine(queryResult9.Min());
                Console.WriteLine(queryResult9.Max());
                Console.WriteLine(queryResult9.Average());
                Console.WriteLine(queryResult9.Sum());
    
            }
        }
    }

     

    复杂类型查询:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace LINQ
    {
        class Customer
        {
            public string ID { get; set; }
            public string City { get; set; }
            public string Country { get; set; }
            public string Region { get; set; }
            public decimal Sales { get; set; }
    
            public override string ToString()
            {
                return "ID: " + ID + " City: " + City + " Country: " + Country + " Region: " + Region + " Sales: " + Sales;
            }
        }
        class Program
        {
            public static void Main(string[] args)
            {
                List<Customer> customers = new List<Customer> {
                  new Customer { ID="A", City="New York", Country="USA", Region="North America", Sales=9999},
                  new Customer { ID="B", City="Mumbai", Country="India", Region="Asia", Sales=8888},
                  new Customer { ID="C", City="Karachi", Country="Pakistan", Region="Asia", Sales=7777},
                  new Customer { ID="D", City="Delhi", Country="India", Region="Asia", Sales=6666},
                  new Customer { ID="E", City="São Paulo", Country="Brazil", Region="South America", Sales=5555 },
                  new Customer { ID="F", City="Moscow", Country="Russia", Region="Europe", Sales=4444 },
                  new Customer { ID="G", City="Seoul", Country="Korea", Region="Asia", Sales=3333 },
                  new Customer { ID="H", City="Istanbul", Country="Turkey", Region="Asia", Sales=2222 },
                  new Customer { ID="I", City="Shanghai", Country="China", Region="Asia", Sales=1111 },
                  new Customer { ID="J", City="Lagos", Country="Nigeria", Region="Africa", Sales=1000 },
                  new Customer { ID="K", City="Mexico City", Country="Mexico", Region="North America", Sales=2000 },
                  new Customer { ID="L", City="Jakarta", Country="Indonesia", Region="Asia", Sales=3000 },
                  new Customer { ID="M", City="Tokyo", Country="Japan", Region="Asia", Sales=4000 },
                  new Customer { ID="N", City="Los Angeles", Country="USA", Region="North America", Sales=5000 },
                  new Customer { ID="O", City="Cairo", Country="Egypt", Region="Africa", Sales=6000 },
                  new Customer { ID="P", City="Tehran", Country="Iran", Region="Asia", Sales=7000 },
                  new Customer { ID="Q", City="London", Country="UK", Region="Europe", Sales=8000 },
                  new Customer { ID="R", City="Beijing", Country="China", Region="Asia", Sales=9000 },
                  new Customer { ID="S", City="Bogotá", Country="Colombia", Region="South America", Sales=1001 },
                  new Customer { ID="T", City="Lima", Country="Peru", Region="South America", Sales=2002 }
               };
    
                var queryResult1 = from c in customers where c.Region == "Asia" select c; //条件查询
                var queryResult2 = customers.Where(c => c.Region == "Asia");//lambda表达式,功能同1
    
                //创建新对象
                var queryResult3 = from c in customers where c.Region == "North America" 
                                   select new { c.City, c.Country, c.Sales };//创建新对象
                var queryResult4 = customers.Where(c => c.Region == "North America").
                    Select(c => new { c.City, c.Country, c.Sales });//lambda表达式,功能同3(注意此处调用顺序)
    
                //Distinct()
                var queryResult5 = (from c in customers select c.Region).Distinct();//查找出不重复的地区
                var queryResult6 = customers.Select(c => c.Region).Distinct();//lambda表达式, 功能同5
    
                //ALL和ANY
                bool anyUSA = customers.Any(c => c.Country == "USA");//是否存在USA的客户
                bool allAisa = customers.All(c => c.Region == "Asia");//是否全是Aisa客户
    
                //多级排序
                var queryResult7 = from c in customers
                                   orderby c.Region, c.Country, c.City
                                   select new { c.ID, c.Region, c.Country, c.City };
                //升降序(ThenBy和ThenByDescending在OrderBy之后)
                var queryResult8 = customers.OrderBy(c => c.Region).ThenByDescending(c => c.Country).
                                   ThenBy(c => c.City).Select(c => new { c.ID, c.Region, c.Country, c.City });
    
                //组合查询
                var queryResult9 = from c in customers group c by c.Region 
                                   into cg select new { TotalSales = cg.Sum(c => c.Sales), Regioin = cg.Key };
                var queryResult10 = from cg in queryResult9 orderby cg.TotalSales descending select cg;//各区域消费总额排名
               
    
                //Take() Skip()
                queryResult9.Take(5);//前五
                queryResult9.Skip(5);//跳过前五
    
                //First() FirstOrDefault()
                queryResult9.First();
                queryResult9.FirstOrDefault();
    
                //集运算符
                //Interserct();Except();Union();
    
                //Join
                var queryResults =
                   from c in customers
                   join o in orders on c.ID equals o.ID
                   select new { c.ID, c.City, SalesBefore = c.Sales, NewOrder = o.Amount, SalesAfter = c.Sales + o.Amount };
            }
        }
    }

     

    LINQTOSQL:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Saku
    {
        class Program
        {
            private static DataClasses1DataContext dataContext = new DataClasses1DataContext();
            public  static List<Teacher> stu = new List<Teacher>();
            static void Main(string[] args)
            {
                var queryResult = from c in dataContext.Teacher where c.tID == "0001" select c;
                var queryResult1 = dataContext.Teacher.Where(c => c.tID == "0001");
    
                foreach(var item in queryResult1)
                {
                    Console.WriteLine(item.tName);
                }
            }
            static Teacher Add(Teacher t)//
            {
                dataContext.Teacher.InsertOnSubmit(t);
                dataContext.SubmitChanges();
                return t;
            }
    
    
    
            static Teacher Delete(Teacher t)//删除
            {
                dataContext.Teacher.DeleteOnSubmit(t);
                dataContext.SubmitChanges();
                return t;
            }
    
    
            static void Show()//遍历
            {
                foreach (Teacher tch in dataContext.Teacher)
                {
                    Console.WriteLine(tch.tID + " " + tch.tName + " " + tch.tPassword + " " + tch.tPhone + " " + tch.tAcademy + " " + tch.tDepartment + " " + tch.tRole);
                }
            }
    
            static bool Search(Teacher t)//查找
            {
                var queryResult = from n in dataContext.Teacher where n.tID == t.tID select n;
                if(queryResult!=null)
                {
                    Console.WriteLine("找到" + t.tID);
                    return true;
                }
                else
                {
                    Console.WriteLine("没找到" + t.tID);
                    return false;
                }
            }
    
            static void change()//
            {
                var t = dataContext.Teacher.SingleOrDefault(c => c.tID == "0001");
                t.tPhone = "13437196351";
                dataContext.SubmitChanges();
    
            }
    
        }
    }

     

    未完待续。。

    转载于:https://www.cnblogs.com/Maskisland/p/5904513.html

    展开全文
  • [LinqToSql基础知识]===================================创建数据库必须注意一点:就是不能创建一个空的数据库,也就是说数据库中必须最少要有一个表例子如:System.Data.Linq.DataContext ctx = new DataContext(...

    [LinqToSql基础知识]

    ===================================
    创建数据库必须注意一点:就是不能创建一个空的数据库,也就是说数据库中必须最少要有一个表
    例子如:


    System.Data.Linq.DataContext ctx = new DataContext("server=. ;database=testdb; uid=sa; pwd=");

     ctx.CreateDatabase();

    通过这种方法是不能创建testdb数据库的

    正确创建数据库示例如下:

    1. using System.Data.Linq;
    2. using System.Data.Linq.Mapping;
    3. [Table(Name = "test")]
    4. public class test
    5. {
    6.     [Column(IsPrimaryKey = true, IsDbGenerated = true)]
    7.     public int ID { getset; }
    8.     [Column(DbType = "varchar(20)")]
    9.     public string Name { getset; }
    10. }
    11. public partial class testContext : DataContext
    12. {
    13.     public Table<test> test;
    14.     public testContext(string connection) : base(connection) { }
    15. }
    16.     protected void Button1_Click(object sender, EventArgs e)
    17.     {
    18.         testContext ctx = new testContext("server=.;database=testdb;uid=sa;pwd=");
    19.         ctx.CreateDatabase();
    20.         this.Label1.Text = "恭喜您!成功创建数据库testdb";
    21.     }
    22.     protected void Button2_Click(object sender, EventArgs e)
    23.     {
    24.         testContext ctx = new testContext("server=.;database=testdb;uid=sa;pwd=");
    25.         ctx.DeleteDatabase();
    26.         this.Label2.Text = "恭喜您!成功删除数据库testdb";
    27.     }
    展开全文
  • 包含了101个Linq查询示例,101个LinqToSQL示例,101个LinqToXML示例,101个LinqOverDataSet示例,对Linq的所有查询操作,分组排序,增加删除节点都操作都有,是学习Linq很不错的资料!
  • 说明:Order与OrderDetail是一对多关系,在上面的例子,我们全部删除CustomerID为WARTH和EmployeeID为3 的数据,那么我们不须全部删除呢?例如Order的OrderID为10248的OrderDetail有很多,但是我们只要删除ProductID...

    Insert/Update/Delete操作
    插入(Insert)
    1.简单形式
    说明:new一个对象,使用InsertOnSubmit方法将其加入到对应的集合中,使用SubmitChanges()提交到数据库。

    NorthwindDataContext db = new NorthwindDataContext();var newCustomer = new Customer{    CustomerID = "MCSFT",    CompanyName = "Microsoft",    ContactName = "John Doe",    ContactTitle = "Sales Manager",    Address = "1 Microsoft Way",    City = "Redmond",    Region = "WA",    PostalCode = "98052",    Country = "USA",    Phone = "(425) 555-1234",    Fax = null};db.Customers.InsertOnSubmit(newCustomer);db.SubmitChanges();语句描述:使用InsertOnSubmit方法将新客户添加到Customers 表对象。调用SubmitChanges 将此新Customer保存到数据库。

    2.一对多关系
    说明:Category与Product是一对多的关系,提交Category(一端)的数据时,LINQ to SQL会自动将Product(多端)的数据一起提交。

    var newCategory = new Category{    CategoryName = "Widgets",    Description = "Widgets are the ……"};var newProduct = new Product{    ProductName = "Blue Widget",    UnitPrice = 34.56M,    Category = newCategory};db.Categories.InsertOnSubmit(newCategory);db.SubmitChanges();语句描述:使用InsertOnSubmit方法将新类别添加到Categories表中,并将新Product对象添加到与此新Category有外键关系的Products表中。调用SubmitChanges将这些新对象及其关系保存到数据库。

    3.多对多关系
    说明:在多对多关系中,我们需要依次提交。

    var newEmployee = new Employee{    FirstName = "Kira",    LastName = "Smith"};var newTerritory = new Territory{    TerritoryID = "12345",    TerritoryDescription = "Anytown",    Region = db.Regions.First()};var newEmployeeTerritory = new EmployeeTerritory{    Employee = newEmployee,    Territory = newTerritory};db.Employees.InsertOnSubmit(newEmployee);db.Territories.InsertOnSubmit(newTerritory);db.EmployeeTerritories.InsertOnSubmit(newEmployeeTerritory);db.SubmitChanges();语句描述:使用InsertOnSubmit方法将新雇员添加到Employees 表中,将新Territory添加到Territories表中,并将新EmployeeTerritory对象添加到与此新Employee对象和新 Territory对象有外键关系的EmployeeTerritories表中。调用SubmitChanges将这些新对象及其关系保持到数据库。

    4.使用动态CUD重写(Override using Dynamic CUD)
    说明:CUD就是Create、Update、Delete的缩写。下面的例子就是新建一个ID(主键)为32的Region,不考虑数据库中有没有ID为32的数据,如果有则替换原来的数据,没有则插入。

    Region nwRegion = new Region(){    RegionID = 32,    RegionDescription = "Rainy"};db.Regions.InsertOnSubmit(nwRegion);db.SubmitChanges();语句描述:使用DataContext提供的分部方法InsertRegion插入一个区域。对SubmitChanges 的调用调用InsertRegion 重写,后者使用动态CUD运行Linq To SQL生成的默认SQL查询。

    更新(Update)
    说明:更新操作,先获取对象,进行修改操作之后,直接调用SubmitChanges()方法即可提交。注意,这里是在同一个DataContext中,对于不同的DataContex看下面的讲解。

    1.简单形式
    Customer cust =    db.Customers.First(c => c.CustomerID == "ALFKI");cust.ContactTitle = "Vice President";db.SubmitChanges();语句描述:使用SubmitChanges将对检索到的一个Customer对象做出的更新保持回数据库。

    2.多项更改
    var q = from p in db.Products        where p.CategoryID == 1        select p;foreach (var p in q){    p.UnitPrice += 1.00M;}db.SubmitChanges();语句描述:使用SubmitChanges将对检索到的进行的更新保持回数据库。

    删除(Delete)
    1.简单形式
    说明:调用DeleteOnSubmit方法即可。

    OrderDetail orderDetail =    db.OrderDetails.First    (c => c.OrderID == 10255 && c.ProductID == 36);db.OrderDetails.DeleteOnSubmit(orderDetail);db.SubmitChanges();语句描述:使用DeleteOnSubmit方法从OrderDetail 表中删除OrderDetail对象。调用SubmitChanges 将此删除保持到数据库。

    2.一对多关系
    说明:Order与OrderDetail是一对多关系,首先DeleteOnSubmit其OrderDetail(多端),其次DeleteOnSubmit其Order(一端)。因为一端是主键。

    var orderDetails =    from o in db.OrderDetails    where o.Order.CustomerID == "WARTH" &&    o.Order.EmployeeID == 3    select o;var order =    (from o in db.Orders     where o.CustomerID == "WARTH" && o.EmployeeID == 3     select o).First();foreach (OrderDetail od in orderDetails){    db.OrderDetails.DeleteOnSubmit(od);}db.Orders.DeleteOnSubmit(order);db.SubmitChanges();语句描述语句描述:使用DeleteOnSubmit方法从Order 和Order Details表中删除Order和Order Detail对象。首先从Order Details删除,然后从Orders删除。调用SubmitChanges将此删除保持到数据库。

    3.推理删除(Inferred Delete)
    说明:Order与OrderDetail是一对多关系,在上面的例子,我们全部删除CustomerID为WARTH和EmployeeID为3 的数据,那么我们不须全部删除呢?例如Order的OrderID为10248的OrderDetail有很多,但是我们只要删除ProductID为11的OrderDetail。这时就用Remove方法。

    Order order = db.Orders.First(x => x.OrderID == 10248);OrderDetail od =     order.OrderDetails.First(d => d.ProductID == 11);order.OrderDetails.Remove(od);db.SubmitChanges();语句描述语句描述:这个例子说明在实体对象的引用实体将该对象从其EntitySet 中移除时,推理删除如何导致在该对象上发生实际的删除操作。仅当实体的关联映射将DeleteOnNull设置为true且CanBeNull 为false 时,才会发生推理删除行为。

    使用Attach更新(Update with Attach)
    说明:在对于在不同的DataContext之间,使用Attach方法来更新数据。例如在一个名为tempdb的 NorthwindDataContext中,查询出Customer和Order,在另一个NorthwindDataContext 中,Customer的地址更新为123 First Ave,Order的CustomerID 更新为CHOPS。

    //通常,通过从其他层反序列化 XML 来获取要附加的实体//不支持将实体从一个DataContext附加到另一个DataContext//因此若要复制反序列化实体的操作,将在此处重新创建这些实体Customer c1;List<Order> deserializedOrders = new List<Order>();Customer deserializedC1;using (NorthwindDataContext tempdb = new NorthwindDataContext()){    c1 = tempdb.Customers.Single(c => c.CustomerID == "ALFKI");    deserializedC1 = new Customer    {        Address = c1.Address,        City = c1.City,        CompanyName = c1.CompanyName,        ContactName = c1.ContactName,        ContactTitle = c1.ContactTitle,        Country = c1.Country,        CustomerID = c1.CustomerID,        Fax = c1.Fax,        Phone = c1.Phone,        PostalCode = c1.PostalCode,        Region = c1.Region    };    Customer tempcust =        tempdb.Customers.Single(c => c.CustomerID == "ANTON");    foreach (Order o in tempcust.Orders)    {        deserializedOrders.Add(new Order        {            CustomerID = o.CustomerID,            EmployeeID = o.EmployeeID,            Freight = o.Freight,            OrderDate = o.OrderDate,            OrderID = o.OrderID,            RequiredDate = o.RequiredDate,            ShipAddress = o.ShipAddress,            ShipCity = o.ShipCity,            ShipName = o.ShipName,            ShipCountry = o.ShipCountry,            ShippedDate = o.ShippedDate,            ShipPostalCode = o.ShipPostalCode,            ShipRegion = o.ShipRegion,            ShipVia = o.ShipVia        });    }}using (NorthwindDataContext db2 = new NorthwindDataContext()){    //将第一个实体附加到当前数据上下文,以跟踪更改    //对Customer更新,不能写错    db2.Customers.Attach(deserializedC1);    //更改所跟踪的实体    deserializedC1.Address = "123 First Ave";    //附加订单列表中的所有实体    db2.Orders.AttachAll(deserializedOrders);    //将订单更新为属于其他客户    foreach (Order o in deserializedOrders)    {        o.CustomerID = "CHOPS";    }    //在当前数据上下文中提交更改    db2.SubmitChanges();}语句描述:从另一个层中获取实体,使用Attach和AttachAll将反序列化后的实体附加到数据上下文,然后更新实体。更改被提交到数据库。

    使用Attach更新和删除(Update and Delete with Attach)
    说明:在不同的DataContext中,实现插入、更新、删除。看下面的一个例子:

    //通常,通过从其他层反序列化XML获取要附加的实体//此示例使用 LoadWith 在一个查询中预先加载客户和订单,//并禁用延迟加载Customer cust = null;using (NorthwindDataContext tempdb = new NorthwindDataContext()){    DataLoadOptions shape = new DataLoadOptions();    shape.LoadWith<Customer>(c => c.Orders);    //加载第一个客户实体及其订单    tempdb.LoadOptions = shape;    tempdb.DeferredLoadingEnabled = false;    cust = tempdb.Customers.First(x => x.CustomerID == "ALFKI");}Order orderA = cust.Orders.First();Order orderB = cust.Orders.First(x => x.OrderID > orderA.OrderID);using (NorthwindDataContext db2 = new NorthwindDataContext()){    //将第一个实体附加到当前数据上下文,以跟踪更改    db2.Customers.Attach(cust);    //附加相关订单以进行跟踪; 否则将在提交时插入它们    db2.Orders.AttachAll(cust.Orders.ToList());    //更新客户的Phone.    cust.Phone = "2345 5436";    //更新第一个订单OrderA的ShipCity.    orderA.ShipCity = "Redmond";    //移除第二个订单OrderB.    cust.Orders.Remove(orderB);    //添加一个新的订单Order到客户Customer中.    Order orderC = new Order() { ShipCity = "New York" };    cust.Orders.Add(orderC);    //提交执行    db2.SubmitChanges();}语句描述:从一个上下文提取实体,并使用 Attach 和 AttachAll 附加来自其他上下文的实体,然后更新这两个实体,删除一个实体,添加另一个实体。更改被提交到数据库。


    展开全文
  • Linq二 LinqToSql

    2013-12-22 21:38:00
    虽然微软已经停止更新了LinqToSql,但是目前的已完全满足目前的需求. 第一步:添加LinqToSql 第二步:将其关联的Sqlserver数据库 第三步:数据库已变成实体类 第四步:可以对数据库进行增删改查操作 ...
  • LInqToSql 增删改

    2012-04-18 18:50:00
    此文章出处来源于网络,本人稍作修改 ...这样会生成LinqToSql所需的实体类 新建数据表: 客户端留言显示效果: 后台管理留言效果: 前台添加 前台页面: 1 <div> 2 3 ...
  • LinqToSql ,EF:外键实体的CRD 2011-03-06 21:56:26|分类:linq|标签:编程|字号订阅 接触LinqTosql是很久的事情了,之前一直在拼接字符串,所以一开始就很喜欢这种ORM的方式,强类型用的爽啊,最近...
  • LinqToSql 小例子

    2013-11-01 17:12:00
    Console.WriteLine("测试删除----请输入分类名称"); name = Console.ReadLine(); Category catDel = dataContext.Category.First(c => c.Name == name); dataContext.Category.DeleteOnSubmit(catDel); dataContext...
  • 杂项-ORM:LinqToSQL

    2018-01-04 16:53:00
    ylbtech-杂项-ORM:LinqToSQL LINQ TO SQL 是包含在.NET Framework 3.5 版中的一种 O/RM 组件(对象关系映射),O/RM 允许你使用 .NET 的类来对关系数据库进行建模。 1. 定义返回顶部 然后,...
  • LinqToSql--增删改

    2009-11-18 22:50:00
    生成实体类 新建一个LinqToSql类.如图: 3.从"服务器资源管理器"中拖出Users表,放在该dbml上.如下图: 4.查看dbml代码,结果如下,只需大致看即可: [Table(Name="dbo.Users")] public partial class Users : ...
  • 如何在项目中应用LinqToSql数据库事务 本文主要涉及LinqToSql数据库事务相关,文章不足之处,欢迎您指出。 一、回顾T-SQL中的事务机制: 代码如下: 1 /*加入事务机制后的存储过程*/ 2 ...
  • 1. 我们将对实体的公共操作部分,提取为IRepository接口,比如常见的增加,删除等方法。如下代码: interface IRepository where T : class { IEnumerable FindAll(Funcbool> exp); void Add(T entity); void ...
  • 接触LinqTosql是很久的事情了,之前一直在拼接字符串,所以一开始就很喜欢这种ORM的方式,强类型用的爽啊,最近开始 改为学习ADO.NET 实体框架了:),概念上的东西网上都很多,当我想实现一个简单的外键表操作时,...
  • linqToSql之联合主键的运用

    千次阅读 2009-03-04 17:39:00
    多个关联表联合查询时,如何决定主键,以及各表主键如何运用 var result = from ugu in eDataContext.UserGroupUser join us in eDataContext.User on ugu.UserID equals us.UserID 
  • 如何在项目中应用LinqToSql数据库事务 一、回顾T-SQL中的事务机制: 代码如下: 1 /*加入事务机制后的存储过程*/ 2 createprocedure sp_example 3 @param1int= null, 4 @param2nvarchar(20) = null 5...
  • 本文主要涉及LinqToSql数据库事务相关,文章不足之处,欢迎您指出。 一、回顾T-SQL中的事务机制: 代码如下: /*加入事务机制后的存储过程*/ create procedure sp_example @param1 int = null, @param...
  • LinqToSql会把连接字符串散落地写在多个位置,并且编译后就固定不可更改了。 于是带来了各种不方便。比如在一台机器上配置好的程序拿到另一台机器上,就不得不找出所有散落的连接字符串,然后一一修改才能跑起来。 ...
  • </asp:TemplateField> 操作"> <ItemTemplate> 编辑" CommandName="edit"/> 删除" CommandName="delete"/> </ItemTemplate> <EditItemTemplate> 更新" CommandName="update"/> 取消" CommandName="cancel"/> ...
  • LinqToSql会把连接字符串散落地写在多个位置,并且编译后就固定不可更改了。 于是带来了各种不方便。比如在一台机器上配置好的程序拿到另一台机器上,就不得不找出所有散落的连接字符串,然后一一修改才能跑起来。 ...
  • 本文主要涉及LinqToSql数据库事务相关,文章不足之处,欢迎您指出。  一、回顾T-SQL中的事务机制  代码如下: 1 /*加入事务机制后的存储过程*/ 2 create procedure sp_example 3 @param1 int = null, 4 @param2 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 462
精华内容 184
关键字:

linqtosql删除