Linq not in Query

Source: Internet
Author: User
Tags foreach

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; }
        }
    }
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.