Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below mentioned code is working absolutely fine. But the problem is I have thousands of list in my dailyTransactionPosting List. So it takes plenty of time in verifying and posting that.

I want it to be something like, in its first shot it will verify all the duplicate records by comparing Date and CustomerID and remove those duplicate records.
And in its second shot it will post the complete list to the database.

This is a CoreBanking Project and my code has to be very accurate. Please Help!!! I need this urgently.

C#
public string DailyTransactionPosting(List<DailyTransactionPosting> dailyTransactionPosting)
        {
            DailyTransactionPosting dPosted = new DailyTransactionPosting();
            foreach (DailyTransactionPosting dList in dailyTransactionPosting)
            {
                dPosted = null;
                dPosted = db.Where<DailyTransactionPosting>(a => a.Date == dList.Date && a.CustId == dList.CustId).SingleOrDefault();
                if(dPosted == null)
                {
                    db.Save<DailyTransactionPosting>(aList);
                }
            }
		return Message;
	}
Posted
Comments
Member 11579819 21-Dec-15 12:43pm    
ORMLite is used for the database connection...
[no name] 21-Dec-15 12:55pm    
And why not let the DB decide about the duplicates?
Member 11579819 21-Dec-15 12:59pm    
This module would run on daily basis. So there will be customers with same Customer ID, however the transaction date will be different. So how to do this. I am not that good with Stored Procedures
[no name] 21-Dec-15 13:11pm    
Sorry I was very unprecise. Give me a Chance again. I see two Option:
a.) Check before insert whether unique ID is given. Not that easy in a "parallel environment"
b.) Insert without test and check the result. In case insert failed because of duplicate ID take the Action needed.
Member 11579819 21-Dec-15 13:16pm    
There can't be unique ID for the same Customers because everyday their data will be posted based on their transactions made. And i think db cannot decide this because both Customer ID and date has to be compared.
If it was only one parameter then I could have managed it on database level,but since I have to take care of two parameters,i.e, Transaction date, and Customer ID,that got me stuck.

What say??

1 solution

Please see my comment to the question for the discussion of the valid approaches and some rationale behind them. For some introduction, please see https://en.wikipedia.org/wiki/Unique_key[^].

As I explained in my last comment, it's not all. But further discussion requires more detail on your problem, database schema and your requirements, as well as ultimate goals of your uniqueness criteria, as well as criteria themselves.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900