tags:

views:

152

answers:

1

i am using LINQ to SQL. My Database has 3 columns Ref, Due_amount, Due_Date. Data may look like this, for example.

10 02/08/2009 00:00:00 175.0000
10 02/09/2009 00:00:00 175.0000
10 02/10/2009 00:00:00 175.0000
10 02/11/2009 00:00:00 175.0000
10 02/12/2009 00:00:00 175.0000
10 02/01/2010 00:00:00 175.0000

My code below, returns 6 elements and works, however the Date is always 02/08/2009? if i say change row 2's amount to 150.0000 it then returns the correct date of 02/09/2009? Any ideas?

private static void PopulateInstalments(string Ref, ResponseMessage responseMsg)
        {
            using (DAO dbContext = new DAO())
            {
                IEnumerable<profile> instalments = (from instalment in dbContext.profile
                                                    where instalment.ref == Ref
                                                    select instalment);

                foreach (profile instalment in instalments)
                {
                    if (responseMsg.Instalments == null)
                        responseMsg.Instalments = new ArrayOfInstalments();
                    Instalment tempInstalment = new Instalment();

                    tempInstalment.DueAmount = instalment.Due_amount;
                    tempInstalment.DueDate = instalment.Due_date == null ? "" : instalment.Due_date.ToString();

                    responseMsg.Instalments.Add(tempInstalment);                    
                }
                            }
        }

Thanks Richard

A: 

ensure primary key column is set in source (SQL Server Database in this case)

richard