成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

LINQ表間關(guān)系查詢

開發(fā) 后端
這里介紹LINQ表間關(guān)系查詢,包括介紹EnitityRef與EntitySet相反,用于一對多關(guān)系中的“一”方。與[Association]屬性結(jié)合使用來定義并表示一個關(guān)系。

XX有很多值得學(xué)習(xí)的地方,這里我們主要介紹LINQ表間關(guān)系查詢,包括介紹EntitySet和EntytyRef等方面。

LINQ表間關(guān)系查詢

EnitySet類型為一對多關(guān)系中的“多”方的結(jié)果提供集合。與[Association]屬性結(jié)合使用來定義并表示一個關(guān)系。OtherKey特性,指定在關(guān)聯(lián)的另一端上作為鍵值的、目標(biāo)實體類的一個或多個成員。

EnitityRef與EntitySet相反,用于一對多關(guān)系中的“一”方。與[Association]屬性結(jié)合使用來定義并表示一個關(guān)系。ThisKey表示關(guān)聯(lián)的此端上的鍵值的此實體類成員。

LINQ表間關(guān)系查詢-EntitySet

  1. //Student實體類  
  2. [Table(Name = "Student")]  
  3. public class Student  
  4. {  
  5. [Column(IsPrimaryKey = trueDbType = "int")]  
  6. public int ID;  
  7. [Column(DbType = "varchar(50)")]  
  8. public string StuName;  
  9. [Column(DbType = "bit")]  
  10. public bool Sex;  
  11. [Column(DbType = "int")]  
  12. public int Age;  
  13. private EntitySet _scores;  
  14. [Association(Storage = "_scores"OtherKey = "StudentID")]  
  15. public EntitySet Score  
  16. {  
  17. get { return this._scores; }  
  18. set { this._scores.Assign(value); }  
  19. }  
  20. }  
  21. //Scores實體類  
  22. [Table(Name = "Score")]  
  23. public class Score  
  24. {  
  25. [Column(IsPrimaryKey = trueDbType = "int")]  
  26. public int ID;  
  27. [Column(DbType = "int")]  
  28. public int StudentID;  
  29. [Column(DbType = "float")]  
  30. public float Math;  
  31. [Column(DbType = "float")]public float Chinese;  
  32. [Column(DbType = "float")]  
  33. public float English;  
  34. [Column(DbType = "Datetime")]  
  35. public DateTime Times;  
  36. }  
  37. public class TestDB : DataContext  
  38. {  
  39. public TestDB(string constr)  
  40. : base(constr)  
  41. { }  
  42. public Table Student;  
  43. public Table Scores;  
  44. }  
  45. static string constr = "server=.;database=test;uid=sa;pwd=sa;";  
  46. static void Main()  
  47. {  
  48. //調(diào)用存儲課程  
  49. TestDB Test = new TestDB(constr);  
  50. IQueryable s = from stu in Test.Student  
  51. select stu;  
  52. foreach (var v in s)  
  53. {  
  54. Console.WriteLine(v.StuName);  
  55. foreach (var o in v.Score)  
  56. {  
  57. Console.WriteLine(" 編號:{0},學(xué)生姓名:{1},學(xué)生年齡:{2},
    語文成績:{3},考試時間:{4}", v.ID, v.StuName, v.Age, 
    o.Chinese, o.Times.ToString("yyyy年MM月dd日"));  
  58. }  
  59. }  

表間關(guān)系查詢-EntytyRef

  1. //Student實體類  
  2. [Table(Name = "Student")]  
  3. public class Student  
  4. {  
  5. [Column(IsPrimaryKey = trueDbType = "int")]  
  6. public int ID;  
  7. [Column(DbType = "varchar(50)")]  
  8. public string StuName;  
  9. [Column(DbType = "bit")]  
  10. public bool Sex;  
  11. [Column(DbType = "int")]  
  12. public int Age;  
  13. }  
  14. //Scores實體類  
  15. [Table(Name = "Score")]  
  16. public class Score  
  17. {  
  18. [Column(IsPrimaryKey = trueDbType = "int")]  
  19. public int ID  
  20. [Column(DbType = "int")]  
  21. public int StudentID;  
  22. [Column(DbType = "float")]  
  23. public float Math;  
  24. [Column(DbType = "float")]  
  25. public float Chinese;  
  26. [Column(DbType = "float")]  
  27. public float English;  
  28. [Column(DbType = "Datetime")]  
  29. public DateTime Times;  
  30. private EntityRef _Student;  
  31. [Association(Storage = "_Student"ThisKey = "StudentID")]  
  32. public Student Student  
  33. {  
  34. get { return this._Student.Entity; }  
  35. set { this._Student.Entity = value; }  
  36. }  
  37. }  
  38. public class TestDB : DataContext  
  39. {  
  40. public TestDB(string constr)  
  41. : base(constr)  
  42. { }  
  43. public Table Student;  
  44. public Table Scores;  
  45. }  
  46. static string constr = "server=.;database=test;uid=sa;pwd=sa;";  
  47. static void Main()  
  48. {  
  49. //調(diào)用存儲課程  
  50. TestDB Test = new TestDB(constr);  
  51. var query = from sco in Test.Scores  
  52. select sco;  
  53. foreach (var s in query)  
  54. {  
  55. Console.WriteLine(" 編號:{0},學(xué)生姓名:{1},學(xué)生年齡:{2},
    語文成績:{3},考試時間:{4}", s.StudentID ,s.Student.StuName, 
    s.Student.Age,s.Chinese, s.Times.ToString("yyyy年MM月dd日"));  
  56. }  

【編輯推薦】

  1. LINQ to SQL查詢分析
  2. LINQ查詢架構(gòu)簡單介紹
  3. LINQ to SQL映射關(guān)系概述
  4. LINQ To SQL對象模型淺析
  5. LINQ to SQL映射列描述
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2010-08-24 09:47:05

LINQ to SQL

2009-09-14 18:57:19

LINQ查詢

2009-09-15 15:45:00

Linq聯(lián)合查詢

2009-09-09 16:07:16

Linq實體關(guān)系

2009-09-15 11:29:04

LINQ to SQL

2009-09-15 10:46:04

LINQ to SQL

2009-09-16 10:38:43

LINQ查詢

2009-09-17 13:15:20

LINQ查詢

2009-09-16 10:08:06

LINQ查詢

2009-09-09 16:53:53

LINQ查詢語法

2009-09-10 16:28:17

LINQ查詢

2009-09-14 10:09:26

LINQ查詢結(jié)果

2009-09-14 10:13:02

LINQ查詢操作

2009-09-08 17:27:18

LINQ to Dat

2009-09-07 17:05:10

LINQ進行查詢

2009-09-08 09:24:50

LINQ查詢

2009-09-10 14:47:53

Linq .NET查詢

2009-09-14 10:20:52

LINQ查詢語法

2009-09-15 09:33:46

linq多條件查詢

2009-09-16 10:48:32

LINQ查詢操作
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 中文字幕第十五页 | 成人欧美一区二区三区白人 | av中文在线 | 精品国产欧美一区二区三区成人 | 亚洲一区视频在线 | 国产亚洲成av人片在线观看桃 | 精品久久香蕉国产线看观看亚洲 | 日韩一区二区三区视频在线播放 | 99日韩 | 深夜福利影院 | 99精品欧美一区二区三区 | 精品一区二区视频 | 999久久久久久久 | 久久不卡日韩美女 | 精品精品 | 精品国产乱码久久久久久蜜臀 | 日韩视频精品在线 | 亚洲视频三 | 一区二区三区欧美大片 | a在线免费观看 | 久久久久国产精品一区二区 | 日韩精品专区在线影院重磅 | 美女久久 | 一区二区亚洲 | 91超碰在线 | 欧美一区二区三区在线观看 | 91av在线电影 | 久久久www| 亚洲成人中文字幕 | 国产不卡在线观看 | 欧美一区二不卡视频 | 中文字幕一区二区视频 | 精品欧美一区二区三区 | 天天搞夜夜操 | 在线观看国产精品视频 | 精品在线一区二区三区 | 国产亚洲精品久久久久久豆腐 | 女朋友的闺蜜3韩国三级 | 玩丰满女领导对白露脸hd | 欧美精 | 久久精品亚洲一区 |