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

Task & QueryableEntityCollectionView

3 Answers 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 16 Sep 2013, 08:38 PM
Hi,

I have a myRadGridView binded to a QueryableEntityCollectionView<tableName> property. All worked perfect.
But when I create a Task to fill that property (that was binded to my RadGridView) it appears a messaje saying:

Ocurrió System.InvalidOperationException
  HResult=-2146233079
  Message=El subproceso que realiza la llamada no puede obtener acceso a este objeto porque el propietario es otro subproceso.
  Source=WindowsBase
  StackTrace:
       en System.Windows.DependencyObject.GetValue(DependencyProperty dp)
       en Telerik.Windows.Data.SortDescriptor.get_Member() en c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Sorting\SortDescriptor.cs:línea 22
  InnerException: 


I'm using a MVVM pattern.
The definition of my property binded to my RadGridView is:
private QueryableEntityCollectionView<PROTOCOL> protocolsView;
public QueryableEntityCollectionView<PROTOCOL> ProtocolsView
{
    get { return protocolsView; }
    set
    {
        protocolsView = value;
        RaisePropertyChanged("ProtocolsView");
    }
}


The code I have written in the ViewModel is:
Task.Factory.StartNew(new Action(() =>
            {
 
                DbContext dbContext = new wafintellectEntities(Global.Configuracion.CadenaConexionBDEntity); // connection to BD
                ObjectContext objectContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)dbContext).ObjectContext;
                bool error = false;
                try
                {
                    //ProtocolsView = new QueryableEntityCollectionView<PROTOCOL>(objectContext, "PROTOCOLs");
                    results = new QueryableEntityCollectionView<PROTOCOL>(objectContext, "PROTOCOLs");
                }
                catch (Exception e)
                {
                    error = true;
                    MessageBox.Show("Cadena de conexión errónea. Por favor, configure la conexión con la BD correctamente." + System.Environment.NewLine + e.Message, "Imposible cargar datos", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
                mi.Invoke(new Action(() =>
                {
                    if (!error)
                    {
                        ProtocolsView = results; // "ProtocolsView " is the property binded to my RadGridView
                    }
                }));
}));

The RadGridView is:
<telerik:RadGridView
    x:Name="grdProtocol"
    ItemsSource="{Binding ProtocolsView}"
    AutoGenerateColumns="False"
    SelectionUnit="FullRow"
    GridLinesVisibility="Horizontal"
    CanUserDeleteRows="False"
    CanUserInsertRows="False"
    CanUserFreezeColumns="False"
    RowIndicatorVisibility="Collapsed"
    IsReadOnly="True"
    ShowGroupPanel="False" Grid.ColumnSpan="2">
</telerik:RadGridView>

In the ViewModel, if I change the definition of the property and the code of the Task for the next one code, it works:
private IQueryable protocolsView;
        public IQueryable ProtocolsView
        {
            get { return protocolsView; }
            set
            {
                protocolsView = value;
                RaisePropertyChanged("ProtocolsView");
            }
        }
Task.Factory.StartNew(new Action(() =>
            {
                try
                {
                    wafintellectEntities myEntity = new wafintellectEntities(Global.Configuracion.CadenaConexionBDEntity); // connection to BD
                    ProtocolsView = myEntity.PROTOCOLs; // get the entire data of the table PROTOCOLs
                }
                catch
                {
                    MessageBox.Show("Error al abrir BD...");
                }
            }));



So, my question is:
How can I use QueryableEntityCollectionView<tableName> in a Task?

Thanks.

Sonia.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 19 Sep 2013, 02:47 PM
Hi Sonia,

We are not aware of such an error. Would you please also test with the latest version?
As I can see, you have not defined any sorting for your collection or the RadGridView, haven't you? 
What is the result if you use DataGrid instead of RadGridView? Does it work fine?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Sonia
Top achievements
Rank 1
answered on 22 Sep 2013, 09:05 PM
I have installed version 2013.2.611.40 (v4.0.30319), which I think is the latest one.

The RadGridView is defined as follow:
<telerik:RadGridView
                x:Name="grdProtocol"
                ItemsSource="{Binding ProtocolsView}"
                SelectedItem="{Binding Path=ProtocolSeleccionado, Mode=TwoWay}"
                AutoGenerateColumns="False"
                SelectionUnit="FullRow"
                GridLinesVisibility="Horizontal"
                CanUserDeleteRows="False"
                CanUserInsertRows="False"
                CanUserFreezeColumns="False"
                RowIndicatorVisibility="Collapsed"
                IsReadOnly="True"
                ShowGroupPanel="False" Grid.ColumnSpan="2" >
 
                <telerik:RadGridView.SortDescriptors>
                    <!-- define initial sorting by objid-->
                    <telerik:SortDescriptor Member="objid"/>
                </telerik:RadGridView.SortDescriptors>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding objtype}" Width="*" Header="Objtype" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding objid}" Width="*" Header="Objid" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding action}" Width="*" Header="Action" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding param0}" Width="*" Header="Param0" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding param1}" Width="*" Header="Param1" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding date}" Width="*" Header="Date" DataFormatString="{}{0:d}" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding time}" Width="*" Header="Time" DataFormatString="{}{0:d}" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

As you can see, the RadGridView has defined a sorting.

I haven't proved with a DataGrid because I need the properties RadGridView has (sorting columns, etc.).

Please, if you can tell me if there is something wrong in the code I have:
          QueryableEntityCollectionView<PROTOCOL> results = null;
 
        private void cargarTablaProtocol()
        {
 
            CargandoDatos = false;
 
            Task.Factory.StartNew(new Action(() =>
            {
 
                DbContext dbContext = new wafintellectEntities(Global.Configuracion.CadenaConexionBDEntity);
                ObjectContext objectContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)dbContext).ObjectContext;
                bool error = false;
                try
                {
                    //ProtocolsView = new QueryableEntityCollectionView<PROTOCOL>(objectContext, "PROTOCOLs");
                    results = new QueryableEntityCollectionView<PROTOCOL>(objectContext, "PROTOCOLs");
                }
                catch (Exception e)
                {
                    error = true;
                    MessageBox.Show("Cadena de conexión errónea. Por favor, configure la conexión con la BD correctamente." + System.Environment.NewLine + e.Message, "Imposible cargar datos", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
                mi.Invoke(new Action(() =>
                {
                    if (!error)
                    {
                        ProtocolsView = results; // When this code is executed, the error is thrown.                    
                    }
                    CargandoDatos = true;
 
                }));
 
                
            }));
 
 
        }
 
 
 
 
        private QueryableEntityCollectionView<PROTOCOL> protocolsView;
        public QueryableEntityCollectionView<PROTOCOL> ProtocolsView
        {
            get { return protocolsView; }
            set
            {
                protocolsView = value;
                RaisePropertyChanged("ProtocolsView");
            }
        }

The error that is thrown is attached. That error is produced when the new data stored in the property ProtocolsView (which is binded to the RadGridView) is going to be refreshed to the .xaml (RaisePropertyChanged("ProtocolsView");).

Thanks.

Sonia.
0
Dimitrina
Telerik team
answered on 23 Sep 2013, 01:46 PM
Hello,

The latest version is the Q2 SP1 (2013.2.724.40).

Would it be possible for you to open a support thread and send us a repro project, which we can debug locally? That way we can advise you better.

You can also take a look at this blog post for a reference on how to isolate an issue. 
 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Sonia
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Sonia
Top achievements
Rank 1
Share this question
or