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

The Archive Base Latest Questions

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

My situation is that I screwed up essentially. I inherited my code base about

  • 0

My situation is that I screwed up essentially. I inherited my code base about 1.5 years ago when I took this position and rather than reinventing the wheel, even though I know now that I should have, I kept the DAL in pretty much the same structure as the previous developer.

Essentially there is one file (now at 15k lines of code) that serves as a go between to a bunch of DAO’s that use DataSets and TableAdapters to retrieve data. My xsd files have grown to such size that they cause R# to crash visual studio every time it opens and the intermediary class that is now 15k lines also takes forever for R# to analyze. Not to mention it is ugly, it works but not well, and is an absolute nightmare to debug.

What I have tried thus far is switching to NHibernate. NHibernate is a great library, but unfortunately it was not adaptable enough to work with my application, from what the lead developer says (Fabio Maulo) it is pretty much a combination of my application requirements and the restrictions upon NHibernate when using identity as a database PK strategy.

So now I am back to essentially designing my own DAL. I am looking at a few different patterns for this, but would like to get your DAL design strategies. There are so many ways and reasons to implement a DAL in a particular manner so if you could please explain your strategy and why it was best fit for you I would greatly appreciate it.

Thanks in advance!

Edit: Let me explain why NHibernate did not work since that seems to be the immediate response. My users create a “job” that is actually just a transient representation of my Job class. Within this job they will give it one or a list of weight factors that are also transient at the time of creation. Finally they provide a list of job details that have a particular weight factor associated to them. Because, in the DB, weight factors are unique when I go to persist the job and it cascades down to weight factor it dies when it finds a duplicate weight factor. I tried running a check before assigning the weight factor to the detail (which I didn’t want to do because I don’t want the extra calls to the db) but calling CreateCriteria in NH also causes a flush in the session, according to Fabio, which destroys my cache and thus kills the entire in memory representation of the job. Folks over at the NH mailing list said I should switch over to GUID, but that is not a feasible option as the conversion process would be a nightmare.

  • 1 1 Answer
  • 1 View
  • 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-12T01:16:27+00:00Added an answer on May 12, 2026 at 1:16 am

    My experience with NHibernate is that, while it is packed with features and very high-performance, you will eventually need to become an NHibernate expert in order to fix some unexpected behavior. Reading through the pro-NHibernate answers and seeing

    Hmm , perhaps he uses long running
    Sessions (Session per Business
    Transaction model), and in such an
    approach, using identity is
    discouraged, since it breaks your
    unitofwork (it needs to flush directly
    after inserting a new entity). A
    solution could be to drop the
    identity, and use the HiLo identity
    generator.

    illustrates exactly what I mean.

    What I’ve done is create a base class modeled somewhat off of the ActiveRecord pattern, that I inherit from and mark up the inherited class with attributes that attach it to a stored procedure each for Select, Insert, Update and Delete. The base class uses Reflection to read the attributes and assign the class’s property values to SP parameters, and in the case of Select(), assign the result SQLDataReader’s column values to the properties of a list of generics.

    This is what DataObjectBase looks like:

    interface IDataObjectBase<T>
        {
            void Delete();
            void Insert();
            System.Collections.Generic.List<T> Select();
            void Update();
        }
    

    This is an example of a data class deriving from it:

    [StoredProcedure("usp_refund_CustRefundDetailInsert", OperationType.Insert)]
        [StoredProcedure("usp_refund_CustRefundDetailSelect", OperationType.Select)]
        [StoredProcedure("usp_refund_CustRefundDetailUpdate", OperationType.Update)]
        public class RefundDetail : DataObjectBase<RefundDetail>
        {
    
            [StoredProcedureParameter(null, OperationType.Update, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Insert, ParameterDirection.Output)]
            [StoredProcedureParameter(null, OperationType.Select, ParameterDirection.Input)]
            [ResultColumn(null)]
            public int? RefundDetailId
            { get; set; }
    
            [StoredProcedureParameter(null, OperationType.Update, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Insert, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Select, ParameterDirection.Input)]
            [ResultColumn(null)]
            public int? RefundId
            { get; set; }
            [StoredProcedureParameter(null, OperationType.Update, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Insert, ParameterDirection.Input)]
            [ResultColumn(null)]
            public int RefundTypeId
            { get; set; }
    
            [StoredProcedureParameter(null, OperationType.Update, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Insert, ParameterDirection.Input)]
            [ResultColumn(null)]
            public decimal? RefundAmount
            { get; set; }        
            [StoredProcedureParameter(null, OperationType.Update, ParameterDirection.Input)]
            [StoredProcedureParameter(null, OperationType.Insert, ParameterDirection.Input)]
            [ResultColumn(null)]
            public string ARTranId
            { get; set; }
    
        }
    

    I know it seems like I’m reinventing the wheel, but all of the libraries I found either had too much dependence on other libraries (ActiveRecord + NHibernate, for instance, which was a close second) or were too complicated to use and administer.

    The library I made is very lightweight (maybe a couple of hundred lines of C#) and doesn’t do anything more than assign values to parameters and execute the SP. It also lends itself very well to code generation, so eventually I expect to write no data access code. I also like that it uses a class instance instead of a static class, so that I can pass data to queries without some awkward criteria collection or HQL. Select() means “get more like me”.

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

Sidebar

Related Questions

Situation: text: a string R: a regex that matches part of the string. This
I have this situation that is really irritating me now. At random times with
I have an unavoidable situation that looks like this (simplified): FUNCTION_TO_CALL = y #
Imagine such situation that I have a function like this: Object f() { Object
I have a situation that is well explained in this question: Range intersection /
I just stumbled about some situation that seems weird to me. I might very
So odd situation that I ran into today with OrderBy: Func<SomeClass, int> orderByNumber =
I have a situation that has been partially covered by other answers at SO,
I've run into a strange situation that seems to involve long text overflowing. I'm
Currently in our enterprise we have a situation that i think it's not very

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.