創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的武隆網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
C#的這種entity 很像Annotation java的寫法..
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Linq; using System.Data.Linq.Mapping; namespace LinqObject.models { [Table(Name = "Player")] public class PlayerInfoVO { private string name; [Column(Name="name")] public string Name { get { return name; } set { name = value; } } private int id; [Column(IsPrimaryKey=true,Name="id")] public int Id { get { return id; } set { id = value; } } private int level; [Column(Name = "level_id")] public int Level { get { return level; } set { level = value; } } private EntityRef_myLevel; [Association(Storage="_myLevel",ThisKey="level_id")] public EntityRef _MyLevel { get { return _myLevel; } set { _myLevel = value; } } } }
主表:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Linq; using System.Data.Linq.Mapping; namespace LinqObject.models{ [Table(Name="myLevel")] public class MyLevel{ private int id; [Column(IsPrimaryKey=true,Name="id")] public int Id { get { return id; } set { id = value; } } private string name; [Column(Name="name")] public string Name { get { return name; } set { name = value; } } private EntitySetplayer; [Association(Storage = "player", OtherKey = "Id")] public EntitySet Player { get { return player; } set { player = value; } } } }
刪除 操作 :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using LinqObject.models; namespace LinqObject.mylinq{ public class ConflictLinq{ public void updatePlayer(int id, string name) { AINYLinq db = new AINYLinq(@"Data Source=AONAUFLY\SQLEXPRESS;Initial Catalog=MyLINQ;User ID=sa;Password=******"); IQueryablemyList = from o in db.myLevel where o.Id == 0 && o.Name == "Aonaufly" select o; foreach (var o in myList) { Console.WriteLine("Ainy------------------------"); db.myLevel.DeleteOnSubmit(o); } Console.WriteLine("detail section finished."); Console.ReadLine(); if (myList.Any()) { Console.WriteLine("The parent is presesnt in the Orders collection."); try { var ordF = (from o in db.myLevel where o.Id == 0 select o).First(); db.myLevel.DeleteOnSubmit(ordF); Console.WriteLine(ordF.Name); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } else { Console.WriteLine("There was no parent in the myLevel"); } try { db.SubmitChanges(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } } }