1. SQL query Prototype:
SELECT * from Symptompic where Picpath isn't in (' Picture path 1 ', ' ssssss ', ' sdsd ', ' SDSD ') and Symptomid = 12
LINQ statements:
From the T in DB. Symptompic where!new string[] {"AAA", "BBB", "CCC"}. Contains (t.picpath) && T.symptomid = = 12
Select New
{
T.id,
T.symptomid,
T.picpath,
T.state
}
Example code for the actual project:
var QUERY = from T in Dbcontent.symptompicservice
where!new string[] {"AAA", "BBB", "CCC"}. Contains (t.picpath) && T.symptomid = = 12
Select New
{
T.id,
T.symptomid,
T.picpath,
T.state
};
2. SQL Delete prototype
Delete from Symptompic where Picpath isn't in (' Picture path 1 ', ' ssssss ', ' sdsd ', ' SDSD ') and Symptomid = 12
LINQ statements:
var querysymptompic = from T in db. Symptompic where!new string[] {"AAA", "BBB", "CCC"}. Contains (t.picpath) && T.symptomid = = Select T;
foreach (Var del in querysymptompic)
{
Db. Symptompic.deleteonsubmit (DEL);
}
Db. SubmitChanges ();
Example code for the actual project:
dictionary<string, string> diclist = new dictionary<string, string> ();
list<string> list = new list<string> ();
foreach (var item in diclist)
{
List. ADD (item. Value);
}
string[] Strarray = list. ToArray ();
var querysymptompic = from T in Dbcontent.symptompicservice where!strarray.contains (t.picpath) && T.symptomid = = ID Select t;
foreach (Var del in querysymptompic)
{
DbContent.SymptomPicService.Remove (DEL);
}
Dbcontent.savechanges ();
1 Controller
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using SYSTEM.WEB.MVC;
Using Medicine.bizlogic;
Using Medicine.common;
Using Medicine.entity;
Using System.Configuration;
Using Newtonsoft.json; Namespace Medicine.Api.Controllers {public class Symptomcontroller:controller {[HttpPost] Publ
IC ActionResult updatesymptom (Symptomviewmodel data) {try {//upload file String path = string.
Empty;
dictionary<string, string> dictnew = new dictionary<string, string> ();
dictionary<string, string> dictold = new dictionary<string, string> (); if (!string. IsNullOrEmpty (data. picstring)) {string[] Strarray = data.
Picstring.split (', '); for (int i = 0; i < strarray.length; i++) {String value = Strarray[i].
ToString (); Determine if the old picture is the IF (Stringplus.substringchar (value). ToLower (), 4) = = "http") {Dictold.add ("id" + i.tostring (), Stringplus .
Substringindexofchar (Value, "/upload")); } else {Dictnew.add ("pic" + i.tostring (), Val
UE);
}}} var model = new Symptom () { ID = data.id, UserID = data. UserID, Title = data. Title, Contentdescribe = data.
Contentdescribe,}; BOOL result = biz.
Updatesymptomnew (model, dictnew, dictold);
return ResultMessage.Tool.BoolResult (Result); } catch (Exception ex) {Log4netHelper.Tool.LogError (address + "updatesymptom ()", Ex. MessaGE);
Return ResultMessage.Tool.ErrorResult (ex); }
}
}
}
2, Service database access layer
Using Medicine.common;
Using Medicine.entity;
Using Medicine.iservice;
Using Medicine.repository;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks; Namespace Medicine.service {public class symptompicservice:baseentities, Isymptompicservice {public bo
OL deletebydictionary (Long ID, dictionary<string, string> diclist) {try {
if (Diclist.count > 0) {list<string> List = new list<string> (); foreach (var item in diclist) {list. ADD (item.
Value); } string[] Strarray = list.
ToArray (); var query = from T in Dbcontent.symptompicservice where!strarray.contains (t.picpath) && t.symptomid = = ID Select
T
foreach (var item in query) { DbContent.SymptomPicService.Remove (item);
} dbcontent.savechanges ();
} else {Delete (ID);
} return true; } catch (Exception ex) {Log4netHelper.Tool.LogError (address + "Delete ()", ex.
Message);
return false; }
}
}
}