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

LightSwitch 2011數(shù)據(jù)字段唯一性驗證方案

開發(fā) 開發(fā)工具
我們將談到的是LightSwitch 2011數(shù)據(jù)字段唯一性驗證方案,這個方案其實不復(fù)雜。希望對大家有所幫助。

  LightSwitch 2011 數(shù)據(jù)字段唯一性驗證方案

驗證單表數(shù)據(jù)的某個字段不能輸入重復(fù)值

  設(shè)置實體字段唯一索引

  如果不寫代碼,那么驗證只會在用戶提交[保存]數(shù)據(jù)后,會提示錯誤,很明顯這樣的用戶體驗并不好,因此還需要做以下步驟

  添加自定義驗證

  1.   partial void UserName_Validate(EntityValidationResultsBuilder results)  
  2.   {  
  3.   // results.AddPropertyError("<錯誤消息>");  
  4.   bool duplicateExists = false 
  5.   switch (this.Details.EntityState)  
  6.   {  
  7.   case EntityState.Added:  
  8.   {  
  9.  //基于頁面未提交數(shù)據(jù)的驗證  
  10.   duplicateExists = (from item in DataWorkspace.ApplicationData.Details.GetChanges().AddedEntities.OfType<Employee>()  
  11.  where item.UserName == this.UserName && !string.IsNullOrEmpty(this.UserName)  
  12.   select item).Count() > 1 ? true : false 
  13.   //基于數(shù)據(jù)庫的驗證  
  14.   if (!duplicateExists)  
  15.   duplicateExists = (from Employee emp in DataWorkspace.ApplicationData.Employees.Cast<Employee>()  
  16.   where this.UserName != null &&  
  17.   string.Compare(emp.UserName, this.UserName.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0  
  18.   select emp).Any();  
  19.   break 
  20.   }  
  21.   case EntityState.Modified:  
  22.   {  
  23.   duplicateExists = (from item in DataWorkspace.ApplicationData.Details.GetChanges().ModifiedEntities.OfType<Employee>()  
  24.   where item.UserName == this.UserName && !string.IsNullOrEmpty(this.UserName)  
  25.   select item).Count() > 1 ? true : false 
  26.   if (!duplicateExists)  
  27.   duplicateExists = (from Employee emp in DataWorkspace.ApplicationData.Employees.Cast<Employee>()  
  28.   where this.UserName != null &&  
  29.   string.Compare(emp.UserName, this.UserName.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0  
  30.   select emp).Any();  
  31.   break 
  32.   }  
  33.  }  
  34.   if (duplicateExists)  
  35.   {  
  36.   results.AddPropertyError(string.Format("該用戶[{0}]已經(jīng)存在。", UserName));  
  37.   } 

  運行結(jié)果如下

原文鏈接:http://www.cnblogs.com/neozhu/archive/2011/10/19/2217221.html

【編輯推薦】

  1. 小試一下微軟開發(fā)框架LightSwitch
  2. Visual Studio簡化版推出 供非專業(yè)人員使用
  3. Visual Studio LightSwitch安裝與配置詳解
  4. 詳解Visual Studio 2010輔助敏捷測試
  5. Visual Studio 2010中特殊表格的開發(fā)
責(zé)任編輯:彭凡 來源: 博客園
相關(guān)推薦

2024-05-24 09:29:28

2021-05-20 08:16:57

數(shù)據(jù)庫數(shù)據(jù)軟刪除數(shù)據(jù)

2022-01-27 11:02:04

索引數(shù)據(jù)存儲

2011-07-28 10:02:03

LightSwitch

2009-03-30 11:27:59

中文域名

2021-07-02 06:54:43

分布式環(huán)境ID

2024-11-28 09:47:53

C#互斥鎖Mutex

2024-03-11 05:00:00

Python集合開發(fā)

2017-09-05 09:18:54

OracleCLOB大數(shù)據(jù)

2021-06-15 06:50:08

索引字段數(shù)據(jù)

2024-08-29 09:27:44

LuceneES字段

2024-09-05 16:55:41

2022-07-11 13:34:13

數(shù)據(jù)歸檔

2023-01-12 17:46:37

分庫分表id如何生成

2010-12-06 09:10:02

LightSwitch

2015-07-22 17:21:34

Oracle數(shù)據(jù)字典

2019-10-21 09:55:12

數(shù)據(jù)庫PostgreSQL Oracle

2023-10-26 08:28:31

Python數(shù)據(jù)去重

2013-05-17 09:31:53

Windows AzuOffice 365Visual Stud
點贊
收藏

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

主站蜘蛛池模板: 亚洲综合在线一区二区 | 欧美一区 | 国产欧美精品一区二区色综合 | 日韩午夜电影在线观看 | 精品综合在线 | 久久久91精品国产一区二区精品 | 久久婷婷色 | 国产精品www| 一级毛片视频在线 | 在线观看视频福利 | www.天天操.com| 精品久久久久久亚洲精品 | 国产99久久精品一区二区永久免费 | 在线观看av网站永久 | 色综合天天天天做夜夜夜夜做 | 丝袜 亚洲 另类 欧美 综合 | 午夜一区二区三区在线观看 | 久久国产精品久久国产精品 | 欧美一区二区三区在线观看 | 日韩综合 | 不卡一区二区三区四区 | 91偷拍精品一区二区三区 | 粉嫩av在线 | 精品国产乱码久久久久久蜜退臀 | 欧美精品久久久久 | 九色在线视频 | 日韩三级精品 | 亚洲精品一区二区在线观看 | 网站国产| 日韩欧美亚洲 | 91国内精品久久 | 美女啪啪国产 | 精品一区在线看 | 中文一级片 | 久草视频观看 | 国产亚洲一区二区精品 | 黑人精品xxx一区一二区 | 国产精品国产a级 | 久久夜色精品国产 | 日本在线免费 | 日本超碰|