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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:00+00:00 2026-06-13T02:17:00+00:00

I create two C# Classes Contacts and Customers based on SQL diagram (see the

  • 0

I create two C# Classes Contacts and Customers based on SQL diagram (see the image)
just I want see if I am doing it right and I need some advice ? down database diagram and Classes Customer and Contacts

enter image description here

Customer Class


 public class Customer
    {
        public int CustomerID { get; set; }
        public string Title { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Postion { get; set; }
        public Char Gender { get; set; }
        public DateTime BecomeCustomer { get; set; }     
        public DateTime ModifiedDate { get; set; }



        public Customer() { }


        public static bool AddNewCustomer_Contact(Customer cust,Contacts cont)
        {
            try
            {
                // get a configured DbCommand object
                DbCommand comm = GenericDataAccess.CreateCommand();


                //Set the store Proc name 
                comm.CommandText = "AddNewCustomer_Contact";

                //create new parameter @Title 
                DbParameter param = comm.CreateParameter();
                param = comm.CreateParameter();
                param.ParameterName = "@Title";
                param.Value = cust.Title;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @FirstName
                param = comm.CreateParameter();
                param.ParameterName = "@FirstName ";
                param.Value = cust.FirstName;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @LastName
                param = comm.CreateParameter();
                param.ParameterName = "@LastName";
                param.Value = cust.LastName;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @Postion 
                param = comm.CreateParameter();
                param.ParameterName = "@Postion ";
                param.Value = cust.Postion;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @BecomeCustomer
                param = comm.CreateParameter();
                param.ParameterName = "@BecomeCustomer";
                param.Value = DateTime.Now;
                param.DbType = DbType.DateTime;
                comm.Parameters.Add(param);

                //create new parameter @Gender 
                param = comm.CreateParameter();
                param.ParameterName = "@Gender";
                param.Value = cust.Gender;
                param.DbType = DbType.String;
                comm.Parameters.Add(param);

                //create new parameter @ModifiedDate  
                param = comm.CreateParameter();
                param.ParameterName = "@ModifiedDate";
                param.Value = DateTime.Now;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @LabelContactTypeID
                param = comm.CreateParameter();
                param.ParameterName = "@LabelContactTypeID";
                param.Value = cont.LabelContactTypeID;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @ContactDetails
                param = comm.CreateParameter();
                param.ParameterName = "@ContactDetails";
                param.Value = cont.ContactDetail;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @Status
                param = comm.CreateParameter();
                param.ParameterName = "@Status";
                param.Value = cont.Status;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);

                //create new parameter @Notes
                param = comm.CreateParameter();
                param.ParameterName = "@Notes";
                param.Value = cont.Notes;
                param.DbType = DbType.StringFixedLength;
                comm.Parameters.Add(param);


                return (GenericDataAccess.ExecuteNonQuery(comm) != -1);

            }
            catch
            {
                return false;
            }
        }
    }
Contact Class

public class Contacts
{
    public int ContactsID { get; set; }
    public int CustomerID { get;set; }
    public string ContactDetail { get; set; }
    public bool Status { get; set; }
    public int LabelContactTypeID { get; set; }
    public string Notes { get; set; }


}
  • 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-13T02:17:02+00:00Added an answer on June 13, 2026 at 2:17 am

    While designing a class, the first step would be to identify what classes are needed and what are their attributes/responsibilities. From what I understand, the only high level class that you want to represent is a Customer. By Customer being your high level class, I mean that some attributes of Customer can be constituted by other objects (like Name, Contacts, etc.).

    In addition, some fields like Id are not of any significance outside the database (I assume that the Id in this case is the primary key of your Customer table). If you are bent on basing your class model on the database design (normalized one), then I would suggest that you ‘unnormalize’ your design before proceeding on with the class model. The optimization offered by normalization is only within the scope of a relationship model and usually should not extend to a class which is an in memory representation.

    Furthermore, as suggested by @Yatrix, it would be better to abstract the data access layer from the actual data model.

    Here are some suggestions,

    public class Customer
    {
        // public int CustomerID { get; set; } // Database specific primary key
        public string Title { get; set; } 
        public string FirstName { get; set; } // Is the setter required to be publicly exposed? 
                                              // Or can it be private to the class?
        public string LastName { get; set; }  // FirstName and LastName can be part of a nested class 
                                              // Name, so that the access is more natural... 
                                              // Customer.Name.FirstName 
        public string Postion { get; set; }
        public Char Gender { get; set; } // Can be an enumeration
        public DateTime BecomeCustomer { get; set; }     
        public DateTime ModifiedDate { get; set; }
        public IList<Contact> Contacts { get; private set; } // The getter can be private and you can 
                                                             // expose only some methods like 
                                                             // Customer.GetContactOfType(type)
    
    
        public bool AddContact(Contact contact)
        {
             // ...
        }
    
        public bool RemoveContact(Contact contact)
        {
             // ...
        }       
    }
    
    public class Contact
    {
        public string ContactDetail { get; set; } // Can be named as Detail or something more specific
        public bool Status { get; set; } // Can be enumeration
        public ContactType Type { get; set; } // ContactType is an enumeration
        public string Notes { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create two partial classes for the single aspx file. I am
I need to create two classes and both should be able to send and
I need to create two instances of two classes inside a view controller that
i have an array and want to create two classes that contains the reference
I have implemented two classes, isbn10 and isbn13. I would like to create a
I am trying to associate Contacts with Classes but as two different types. Current_classes
How can I create two classes that have member pointers to each other's class
In Javascript I would like to create two classes: A node, and a node
Is it good in practice to create two different classes in one ruby script
Alright so I'm trying to create a method called: setIncrement(). I have two classes

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.