Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9095157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:31:42+00:00 2026-06-16T23:31:42+00:00

I am using WCF Rest service. I am trying to delete multiple records from

  • 0

I am using WCF Rest service. I am trying to delete multiple records from the repository called “_altProductVersionEntityRepository”
Here is my entire code below

 public Result UpdateProductObject(ProductObjectToSave prodSave)
    {

        IUnitOfWork unitOfWork = new UnitOfWork((IObjectContext)_objectSetFactory);

        var versions = prodSave.VersionDetails;
        var altVersions = prodSave.AlternateVersionDetails;



        foreach (var versionDetail in versions)
        {
            var detail = versionDetail;

            var dbVersionentity = _productVersionEntityRepository.FirstOrDefault(x => x.Id == detail.Id);


            var altVersionEntity = _altProductVersionEntityRepository.FirstOrDefault(x => x.ProductVersionEntityId == detail.Id);

            if (dbVersionentity == null)
            {
                dbVersionentity = new ProductVersionEntity();
                _productVersionEntityRepository.Insert(dbVersionentity);
                dbVersionentity.Id = GetNextTableId("vProductVersion");
                dbVersionentity.CreatedOn = DateTime.Now;


            }


            dbVersionentity.Name = detail.Name;
            dbVersionentity.Code = detail.Code;


            if (detail.Id > 0){

            _productVersionEntityRepository.Update(dbVersionentity);
                if (altVersionEntity != null){
                    _altProductVersionEntityRepository.Delete(altVersionEntity);
                }
            }



        }


        try
        {
            unitOfWork.Commit();
        }
        catch (Exception e)
        {

            return new Result() { Status= e.Message };
        }

        return new Result() { Status= = "Record updated successfully" };

    }

In variable “altVersionEntity” i try to find first record from “_altProductVersionEntityRepository” repository. In this repository there are multiple records but it only delete single record as i am doing FirstOrDefault here. What is way to delete all records. I am using FirstOrDefault because i want to delete records only if they are find otherewise it will throw error.
What is way to delete multiple records? I am still new to WCF so please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:31:43+00:00Added an answer on June 16, 2026 at 11:31 pm

    I have find my own solution. What i do i use find method instead of FirstOrDefault which i was using in above code. I use find method like below

     var altVersionEntity =
                    _altProductVersionEntityRepository.Find(x => x.ProductVersionEntityId == detail.Id);
    

    Then i use variable altVersionEntity and convert to list and then loop through it and delete records from “altProductVersionEntityRepository” repository one by one like below

    var tempList = altVersionEntity.ToList();
                        for (i = 0; i <tempList.Count ; i++)
                        {
                            _altProductVersionEntityRepository.Delete(tempList[i]);
                        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a WCF rest service, then called that from javascript using ajax. Now
I'm trying to expose a simple WCF REST service using data from Linq to
So I'm trying to create a C# WCF REST service that is called by
I've been trying to consume a .net WCF rest service using JAX-WS lately. Due
I'm trying to pass an image from Android to WCF REST service as part
I'm trying to consume a rest service(wcf) using restsharp This is my service [ServiceContract]
I am trying to create a logging service using WCF Rest. It looks something
i am trying to post an image to wcf rest service from silverlight 4
I'm using WCF REST service with API key template and trying to enforce validation
I'm trying to implement a REST service using WCF which will take the parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.