This is a migrated thread and some comments may be shown as answers.

Retrieving items from database view

2 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kris
Top achievements
Rank 1
Kris asked on 09 May 2011, 11:55 PM
I am using the following code to retrieve data from a custom sql db view. It is returning the correct number of rows, but the problem is that each row is the same...the first record being retrieved. See image attached. I use the same code for a direct sql access from a table and it runs correctly. Any ideas?

public List<NoPhoneFollowUp30Day> GetNoPhoneInitialFollowUp30Days(string userID)
{
    List<NoPhoneFollowUp30Day> NoPhone30DaysYearList = new List<NoPhoneFollowUp30Day>();
    string[] statesArray = new string[0];
 
    IQuery q1 = sc.GetSqlQuery(@"SELECT [TelephoneReportID]
                                  ,[FacilityID]
                                  ,[Facility Name]
                                  ,[Date Time Received]
                                  ,[Company]
                                  ,[Last Name]
                                  ,[First Name]
                                  ,[DateTimeReceived]
                                  ,[ReportingState]
                              FROM [CRERNS].[dbo].[NoPhoneFollowUp_30Days]
                                ORDER BY DateTimeReceived DESC", typeof(NoPhoneFollowUp30Day), null);
 
    return DataDriver.Utilities.ToList<NoPhoneFollowUp30Day>(q1.Execute().ToList());
}
public static class Utilities
{
    public static List<T> ToList<T>(ArrayList arrayList)
    {
        List<T> list = new List<T>(arrayList.Count);
        foreach (T instance in arrayList)
        {
            list.Add(instance);
        }
        return list;
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 12 May 2011, 05:42 PM
Hi Kris,

This behavior is caused by the fact that your persistent class does not have an identity field. This is usually observed with classes mapped to views, because the views do not provide information about primary key columns and no identity members are automatically created. What you need to do is set one or more of the class properties as identities. It is required that the member (or the combination of members) you have marked as identity can identify uniquely each row of the view, otherwise you will get duplicating objects, as you have already noticed.
To set a property as identity, just select it in the designer, open the Properties pane (or press F4) and set the Identity option to True. I hope that helps.

Regards,
Alexander
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Kris
Top achievements
Rank 1
answered on 12 May 2011, 06:36 PM
Awesome..., that was the issue. I had the wrong field declared as the identity.

Thanks
Tags
General Discussions
Asked by
Kris
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Kris
Top achievements
Rank 1
Share this question
or