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

LINQ expression needed

2 Answers 71 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Santhosh
Top achievements
Rank 1
Santhosh asked on 18 Sep 2009, 12:01 PM
Hi all,

I am struggling to write to code for pulling values from the Scope.

Here is my problem.. I think its a simple issue, Can anybody help me


My Task Class is

[Telerik.OpenAccess.Persistent]
    public class Tasks
    {
        public Tasks()
        {
            Assignee = new Resource();
            resource = new Resource();
            duration = 0;
            Edits = new List<TaskEdits>();
        }
        public Guid tuid = Guid.Empty;
        private string name = string.Empty;
        private string description = string.Empty;
        private Resource assignee;
        private Resource resource;
        private DateTime startDate = DateTime.MinValue;
        private int duration;
        private string project_name = string.Empty;
        [Telerik.OpenAccess.Depend()]
        public  IList<TaskEdits> edits = null;
        public string Name
        {
            get
            {
                return name ;
            }
            set
            {
                name = value;
            }
        }
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        public Resource Assignee
        {
            get
            {
                return assignee;
            }
            set
            {
               assignee = value;
            }
        }
        public DateTime StartDate
        {
            get
            {
                return startDate;
            }
            set
            {
                startDate = value;
            }
        }
        public int Duration
        {
            get { return duration; }
            set { duration = value; }
        }
        public Resource Resource
        {
            get { return resource; }
            set { resource = value; }
        }
        public string Project_Name
        {
            get{ return project_name;}
            set { project_name = value;}
        }
        public Guid TUID
        {
            get{ return tuid;}
            set { tuid = value; }
        }
        public IList<TaskEdits> Edits
        {
            get { return edits; }
            set { edits = value; }
        }
    }


And Tasknotes Class called as TaskEdits


[Telerik.OpenAccess.Persistent]
    public class TaskEdits
    {
        public  TaskStatus tstatus = TaskStatus.Not_Started;
        private DateTime finisheddate = DateTime.MinValue;
        private string note = string.Empty;
        public DateTime edate = DateTime.MinValue;
        public TaskStatus Status
        {
            get { return tstatus; }
            set { tstatus = value; }
        }
        public DateTime FinishDate
        {
            get { return finisheddate; }
            set { finisheddate = value; }
        }
        public string Note
        {get{ return note;}
        set{ note = value;}}
        public DateTime EditedDate
        {
            get { return edate; }
            set { edate = value; }
        }
    }
    public enum TaskStatus
    {
        Not_Started,
        In_Progress,
        Completed
    }


Now i need to pull all the Tasks, which ever having the [TaskEdits - Status] is 'Completed'.

I need a LINQ expression for this.

2 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 22 Sep 2009, 12:52 PM
Hi santhosh,

You should use the following query:
var result = (from t in scope.Extent<Tasks>()
            from x in t.Edits 
            where x.Status == TaskStatus.Completed 
            select t).Distinct(); 

Unfortunately, this type of queries is not supported in the current versions of the product. The functionality is implemented but has not been released yet. It should take place in the next version of Telerik OpenAccess ORM. Until then, you can use this query instead:
var result = (from t in scope.Extent<Tasks>().ToList() 
          from x in t.Edits 
          where x.Status == TaskStatus.Completed 
          select t).Distinct(); 
It would first retrieve all Tasks objects and do the filtering in memory, which could be slow in some cases but is the only workaround at this point. We will notify you when the new version is available.

Kind regards,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alexander
Telerik team
answered on 14 Oct 2009, 02:29 PM
Hello santhosh,

A new Internal build (version 2009.2.1013.1) has been released. It contains the functionality needed to execute the query mentioned in the previous post. You should be able to download it from your account.

Regards,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
LINQ (LINQ specific questions)
Asked by
Santhosh
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or