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 4330068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:54:42+00:00 2026-05-21T09:54:42+00:00

Often I have to deal with a save method which has to check a

  • 0

Often I have to deal with a save method which has to check a few things before saving to the database.

Things I check for, for example, are empty properties, and values which depends on other properties.

I am always struggling on how to implement such a things. The questions I ask myself are:

  • Should I use a boolean as a return value for the Save method? And in the client code, check of it is false, show the end-user a messagebox with: “Saving failed”. But the problem is, I can’t show the user why saving is failed. So I don’t like this one very much.
  • In my Save methods, should I throw an Exception? So when a check fails, a Exception is thrown?
  • Do nothing. When a check fails, just don’t do anything. But I think this is not really a option.

I was wondering, how do you implement this? Is there kind of a pattern?

  • 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-21T09:54:43+00:00Added an answer on May 21, 2026 at 9:54 am

    imho it’s not up to the save method to validate the object. It should be valid when Save is called. It’s therefore OK to throw an exception if the object is not specified correctly.

    As for validation, there are built in framework in .NET which is called DataAnnotations. Use it for easier validations in all layers.

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

Sidebar

Related Questions

I have to deal with JSON files larger than 1MB, which often contain long
When I'm debugging, I often have to deal with methods that does not use
I often have nothing more than an FTP access to a server on which
I often have to deal with XML documents that contain namespaced elements, but doesn't
I often have comment forms and lots of users post things such as !!!!!!!!!!!
We are using Redis as a caching server, and often have to deal with
Before using the Task Parallel Library, I have often used CorrelationManager.ActivityId to keep track
I often have to sort a dictionary (consisting of keys & values) by value.
I often have data in Excel or text that I need to get into
I often have to convert a retreived value (usually as a string) - and

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.