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 ...
}
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
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?
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?
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
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.
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.
Hi:
EntityFrameworkCoreDataSource: Support for .NET 5/6/7 is ready?
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?