自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

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

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

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

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

  添加自定義驗(yàn)證

  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ù)的驗(yàn)證  
  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ù)庫的驗(yàn)證  
  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.   } 

  運(yùn)行結(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-09-05 16:55:41

2024-08-29 09:27:44

LuceneES字段

2022-07-11 13:34:13

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

2023-01-12 17:46:37

分庫分表id如何生成

2015-07-22 17:21:34

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

2010-12-06 09:10:02

LightSwitch

2019-10-21 09:55:12

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

2023-10-26 08:28:31

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

2016-01-25 09:38:24

云存儲公共云
點(diǎn)贊
收藏

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