I have been trying to move my project to MVVM for some time.
There is a DataTable I am getting from Database:
MainProcess.cs:
public static DataTable CustomersInLiinos = new DataTable();
public static void MergedTable()
{
var t1 = ConnectAndRetriveDatatatableS(); // t1
var t2 = ConnectAndRetriveDatatatableF(); // t2
CustomersInLiinos = t1.Copy();
CustomersInLiinos.Merge(t2);
}
ViewModel.cs:
private async Task ExecuteLoadMainTableDataAsync(object commandParameter)
{
if (MainProcess.CheckForVPNInterface())
{
if (MainProcess.CustomersInLiinos != null)
{
this.HasProgress = true;
IEnumerable<Item> resultItems = await LoadMainTableDataAsync();
this.Items = new ObservableCollection<Item>(resultItems);
EnableItemsFiltering();
this.HasProgress = false;
}
}
else
{
throw new VpnInterfaceException("Please, check your VPN connection!");
}
}
Inside ViewModel.cs I have also this:
public Task<DataView> LoadMainTableDataAsync()
{
return Task.Run(() =>
{
MainProcess.MergedTable();
return MainProcess.CustomersInLiinos.DefaultView;
});
}
Curently I am having an error pointing at await LoadMainTableDataAsync();
:
Severity Code Description Project File Line Suppression State Error CS0266 Cannot implicitly convert type 'System.Data.DataView' to 'System.Collections.Generic.IEnumerable<Liinos_inspector_FilterTest.Item>'. An explicit conversion exists (are you missing a cast?)
I understand that there is an error in LoadMainTableDataAsync
? I am loading data to DataView and should load to IEnumerable instead?
Would it be easier to utilize this:
public class JoinedFandS
{
public string YRNRO { get; set; }
public string HAKUNIMI { get; set; }
public string NIMIA { get; set; }
public string NIMIB { get; set; }
}
public static IEnumerable<JoinedFandS> GetMyJoinedResult()
{
var t1 = ConnectAndRetriveDatatatableS(); // t1
var t2 = ConnectAndRetriveDatatatableF(); // t2
var firstTable = ...
var secondTable = ...
var results = firstTable.Concat(secondTable);
return results;
}
EDIT:
<Window x:Class="Liinos_inspector_FilterTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Liinos_inspector_FilterTest="clr-namespace:Liinos_inspector_FilterTest"
mc:Ignorable="d"
Title="Liinos database inspector" Height="672" Width="1000" Icon="Images/logo_icon-small.jpg" Background="White" MinWidth="1000">
<Window.DataContext>
<ViewModel />
</Window.DataContext>
Severity Code Description Project File Line Suppression State Error XLS0414 The type 'ViewModel' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. Liinos inspector FilterTest MainWindow.xaml 11
and
Severity Code Description Project File Line Suppression State Error XDG0008 ViewModel is not supported in a Windows Presentation Foundation (WPF) project. Liinos inspector FilterTest MainWindow.xaml 11
What should I use instead of ViewModel?