Telerik Forums
UI for WPF Forum
0 answers
46 views

Hi,

i have two database models:

public class LogOrder
{
    [Key]
    public long Id { get; set; }

    public string Name { get; set; }
	...

    [Display(AutoGenerateField = false)]
    [InverseProperty(nameof(LogOrderUpdate.Order))]
    public virtual ICollection<LogOrderUpdate> Updates { get; set; }

    #region View

    [Display(AutoGenerateField = false)]
    public LogOrderUpdate LastUpdate
    {
        get
        {
            if (Updates != null && Updates.Any())
            {
                return Updates.MaxBy(x => x.Time);
            }

            return null;
        }
    }
    
    #endregion

     ctor ...
}
and
public class LogOrderUpdate : IEntity
{
    [Key]
    public long Id { get; set; }

    public DateTime Time { get; set; }
    ...
}

used in a ViewModel

private QueryableEntityCoreCollectionView<LogOrder> entityCollectionView;

public QueryableEntityCoreCollectionView<LogOrder> EntityCollectionView
{
    get { return entityCollectionView; }
    set
    {
        this.entityCollectionView = value;
        this.OnPropertyChanged(nameof(EntityCollectionView));
    }
}
private readonly LogOrderContext objectContext;

public ViewModel()
{
    objectContext = new LogOrderContext();
    entityCollectionView = new QueryableEntityCoreCollectionView<LogOrder>(objectContext, objectContext.LogOrders, new Collection<string>() { nameof(LogOrder.Updates) } );
}

shown in xaml

<telerik:RadGridView 
    AutoGenerateColumns="False"
    ItemsSource="{Binding EntityCollectionView}"
    IsReadOnly="True" 
    Name="LogOrderGrid">
    <b:Interaction.Behaviors>
        <behaviors:RadGridLayoutBehavior />
    </b:Interaction.Behaviors>
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Id" UniqueName="Id" DataMemberBinding="{Binding Path=Id}"/>
        <telerik:GridViewDataColumn Header="Name" UniqueName="Name" DataMemberBinding="{Binding Path=Name}"/>
        <telerik:GridViewDataColumn Header="Time" UniqueName="LastUpdateTime" DataMemberBinding="{Binding Path=LastUpdate.Time}"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

Everything works as expected

But when I try to sort or filter the grid i get a System.InvalidOperationException

System.InvalidOperationException: 'The LINQ expression 'DbSet<LogOrder>()
    .OrderBy(l => l.LastUpdate.Time)' could not be translated. Additional information: Translation of member 'LastUpdate' on entity type 'LogOrder' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'

It tries to query the "non database" property directly from the database -> .OrderBy(l => l.LastUpdate.Time)'

and the grid gets empty

I know combining db model and view properties are not a good approach but with the QueryableEntityCoreCollectionView I have to!?
Is there any annotation for those properties like [NonDbProperty] i can control this behavior?
Or is my approach completely wrong?

thank you in advance,
Marco

Marco
Top achievements
Rank 1
Iron
Iron
Iron
 asked on 16 Aug 2023
0 answers
55 views
i have three xaml pages for my wpf panel. One is the main page which in the xaml has a <content x:Name=“page2”> defined and the page 2 is where my button is. This button has a mouse down event when pressed should show page 3. However i cant achieve that now with my implementation. How can i be able to do that? I am using xaml and code behind not mvvm
Yohannes
Top achievements
Rank 1
 asked on 14 Jul 2023
1 answer
60 views

HI:

I was using ICollectionView to syncronize dataform with dataGrid. Im testing RadEntityFrameworkCoreDataSource and works perfectly without the need to implement ICollectionView . (I assume it does internally). Could you give me and advise about wish one is better?

Stenly
Telerik team
 answered on 22 Nov 2022
1 answer
49 views

Hi:

I'm confused about the best approach to create a crud with Telerik and EntityFramewok 7.0. In some of your samples, I found the use of ICollectionView, but in others QueryableEntityCollectionView and in the mvm sample of RadEntityFrameworkCoreDataSource documentation I was expecting RadEntityFrameworkCoreDataSource, but instead, it uses QueryableEntityCollectionView. Could you help me to understand the differences and advantages of each approach?

Martin Ivanov
Telerik team
 answered on 18 Nov 2022
1 answer
63 views

HI:

I have this query:

 _clientes = new QueryableCollectionView(clientes.Include(c => c.PkCiudadNavigation).ToList()); and I what to change it RadEntityFrameworkCoreDataSource , how Can I Specify this include with RadEntityFrameworkCoreDataSource 

Thanks for your help

Martin Ivanov
Telerik team
 answered on 18 Nov 2022
0 answers
47 views

HI:

In entity framework im using FromSqlRaw to run a sql query:

(db.FsgAcuerdos.FromSqlRaw("Select * From FSG_ACUERDOS ").ToList()

How can I do it with RadEntityFrameworkCoreDataSource 

 

Thanks in advance.

Sami
Top achievements
Rank 2
Iron
Iron
Iron
 asked on 17 Nov 2022
0 answers
56 views

HI:

I read the documentation about cancel option, and all that I saw says that you should implement interface IEditableObject.  I have a project that doesn't implement it and cancel button works perfectly over observable collection against entity framework throw CollectionViewSource:


            ICollectionView c = CollectionViewSource.GetDefaultView(db.Clientes.FromSqlRaw("Select * From CLIENTES ").ToList());
            dbGrid.ItemsSource = c;
            dataForm.ItemsSource = c;

 

in other project with other table it doesnt work unless my object implments IEditableObject, ¿Why?

Is necesary implement IEditableObject incluiding if use EnityFramework over observable collection? Is necesary implment this IedtiableObject interfase also if I use RadEntityFrameworkCoreDataSource instead  ICollectionView ?

 

Thanks in advance for your dvise.

 

Sami
Top achievements
Rank 2
Iron
Iron
Iron
 asked on 17 Nov 2022
1 answer
34 views
<p>HI;</p><p>EntityFrameworkCoreDataSource is ready for production? Can I download it?</p>
Martin Ivanov
Telerik team
 answered on 17 Nov 2022
1 answer
53 views

Hi:

EntityFrameworkCoreDataSource: Support for .NET 5/6/7 is ready?

 

Martin Ivanov
Telerik team
 updated answer on 02 Nov 2022
1 answer
86 views

Hi:

Could you advise me about the best way to create a crud with EntiyFramework 6 using radgrid and radDataForm?

The use of EntityFrameworkCoreDataSource is good idea?

Martin Ivanov
Telerik team
 answered on 02 Nov 2022
Narrow your results
Selected tags
Tags
+? more
Top users last month
Dominik
Top achievements
Rank 1
Giuliano
Top achievements
Rank 1
Dominic
Top achievements
Rank 1
Glendys
Top achievements
Rank 1
NoobMaster
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Dominik
Top achievements
Rank 1
Giuliano
Top achievements
Rank 1
Dominic
Top achievements
Rank 1
Glendys
Top achievements
Rank 1
NoobMaster
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?