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

  • Home
  • SEARCH
  • 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 6929059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:10+00:00 2026-05-27T11:16:10+00:00

I have a method in my code which must have a void return type

  • 0

I have a method in my code which must have a void return type and it must only take a single, specific parameter. I need to return something from it.

To give you the details: I have a WCF service which has SQL server access on it. It had code generated by a program called SQLMetal.exe. This gave me a partial class (DataContext) with partial methods. I’m building the other part of this partial class, and these partial methods are things like ‘InsertUser’ or ‘DeleteUser’. They aren’t implemented in the other part of the partial class, but I guess this means I have to implement them. That’s fine and all, but if they’re partial methods, they have to have a void return type.

So what if I want to return something from one of these? I mean, an application can hook up to this service, and can use it to access database information. That application’s going to need to know if there was an error on the service side.

So it’s a partial method with a void return type and a predefined set of parameters.

What to do?

Edit: More details!

Firstly, why can’t I change the generated code? Well, that is a good suggestion, but I have a concern about that. The reason it’s generated as it is is in order to minimuse future coding problems if the database were to change and you had to re-generate the code.

Secondly, some code:

[System.Data.Linq.Mapping.DatabaseAttribute(Name = "HVD01")]

public partial class HydraDataContext : System.Data.Linq.DataContext

{



    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();



    #region Extensibility Method Definitions

    partial void OnCreated();

    partial void InsertClient(Client instance);

    partial void UpdateClient(Client instance);

So that’s the relevant part of the generated code.

Then is my part. This is in the other partial class which marries up to the generated one.

public void UpdateClient(Client client)
    {
        //Primary key can't be zero
        if (client.ClientID == 0)
            return;


        dc.Clients.Attach(client, true);

        dc.SubmitChanges();

    }

Obviously there are potential things that need to be returned.

How about exceptions? Well if I throw one on the WCF service, I don’t think the application will get it (I may be wrong here). The application consumes the service, but I don’t think throwing an exception on the service would reach the consuming application. Would it?

Maybe just changing the functions is for the best. I just figured that the whole point was to leave the generated code as much as possible in case you needed to regenerate it.

Thanks again.

  • 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-05-27T11:16:10+00:00Added an answer on May 27, 2026 at 11:16 am

    These partial methods you mention are designed to allow you to hook into the internal workings of LinqSql – they are not really supposed to become the public API of your data access layer. You can add any other public methods you like into the DataContext class (with no signature restrictions) – although I’d recommend looking into the Repository Pattern.

    Edit In response to comment

    Here’s a psuedo example of a simple repository implementation which can act as a public wrapper around the DataContext, and can return contextual information about the result of the operation as you described in your post..

    public class ClientRepository
    {
        public ClientRepository()
        {
            this.DataContext = new HydraDataContext();
        }
    
        private HydraDataConetxt DataContext { get; set; }
    
        // DBResult is a made up class which returns some info about the operation...
        public DBResult Insert(Client client)
        {
            try
            {
                this.DataContext.Clients.InsertOnSubmit(client);
                this.DataContext.SubmitChanges();
    
                 return DBResult.Success;
            }
            catch (Exception error)
            {
                 return DBResult.Failed(error.Message);
            }
        }
    }
    

    Hope that gives you food for thought 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which works just fine when the method is POST,
I have a couple of method attributes which do some logging. Our logging code
I have this code: s(x => x.Open()); s is a method which calls one
I have a method in my Python code that returns a tuple - a
I have the following method in my code: private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)
I have a static method in my code that I would like somehow to
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method in my VBA code that needs to be assigned to
I have a method that's about ten lines of code. I want to create
In code-behind of an ASP.NET page I have this method: public string TestFunc() {

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.