LINQ to Entities and a GridControl-VBForums
Results 1 to 4 of 4

Thread: LINQ to Entities and a GridControl

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    LINQ to Entities and a GridControl

    Hi,

    I am binding a grid control (from DevExpress) using the following LINQ query:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Linq;
    using System.Windows.Forms;
    using DevExpress.XtraEditors;
    
    namespace WindowsFormsApplication1 {
    
        public partial class frmMain : DevExpress.XtraEditors.XtraForm {
    
            Models.beachreach_dataEntities objDB = new Models.beachreach_dataEntities();
    
            public frmMain() {
                InitializeComponent();
            }
    
            private void frmMain_Load(object sender, EventArgs e) {
    
                gcVans.DataSource = from v in objDB.vans
                                           select new Models.clsDisplayVan {
    
                                               van_name = v.van_name,
                                               van_school_name = v.school.school_name,
                                               van_phone = v.phone,
                                               van_capacity = (int) v.capacity,
                                               is_offline = (int) v.is_offline,
                                               is_prayer_room = (int) v.is_prayer_room
    
                                           };
    
    
    
            }
    
    }
    Here is my question: The datasource for my entity context is on a remote server. I am wanting to poll that server at a specified interval using a timer. What would be the best way to run this query again and refresh the datagrid? I realize that I could simply re-run the code in the Load event, but it resets any selection/grouping/filtering etc when you set the datasource property.

    Thanks for any assistance as I am new to the Entity Framework (mostly a LAMP dev)!
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,089

    Re: LINQ to Entities and a GridControl

    You should populate a collection, bind that to a BindingSource and then bind that to your control. You can then update the collection as required and call ResetBindings on the BindingSource. You could also use a collection that implements IBindingList itself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    Re: LINQ to Entities and a GridControl

    Would it suffice for the collection to be the entity set itself? If so, since the car keyword is a local scoped variable, how could I update that set from another method elsewhere? Perhaps I'm not understanding the whole picture. Thanks for your patience.
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,089

    Re: LINQ to Entities and a GridControl

    Variables have scope. Objects don't. You need a single collection that you can bind to the control and leave it bound. You need to make changes to that one collection rather than creating a new collection and binding that. How you do that is up to you. The one collection can be referred to by as many different variables as you like. If you want to be able to refer to the one object from multiple methods, or even the same method multiple times, then you must be able to access it somehow. Again, how you do that is up to you. It might be a property, field or parameter.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.