How to Load, Add, Update and Delete records from database using EntityFramework in WPF, MVVM

How to Load, Add, Update and Delete records from database using EntityFramework in WPF, MVVM

Wpf World

3 года назад

22,948 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

VIVEK KUMAR YADAV
VIVEK KUMAR YADAV - 08.08.2023 09:01

Can you share the code thanks in advance

Ответить
BloodyClash
BloodyClash - 19.07.2022 21:27

Half of the stuff is skipped...so not too helpfull overall.

Ответить
John Moises Paunlagui
John Moises Paunlagui - 22.06.2022 20:16

Cannot implicitly convert type string to int in addemployee

Ответить
Tallal Sajid
Tallal Sajid - 10.06.2022 01:11

Why didn't you show the custom command kindly try to make the complete video and don't put the other commands video link in the reply give the source code of commands you used in this video

Ответить
David Santos
David Santos - 20.05.2022 20:16

where did this "EmployeeEntities" come from?

Ответить
Trẻ Người lính
Trẻ Người lính - 29.03.2022 15:33

can you show code about class Command, I can not see code Command class?

Ответить
Zerg Zerg
Zerg Zerg - 19.01.2022 23:53

Hello, again. Could you help me please? I follow your tutorial and try to add DeleteCommand, but for some reason the DELETE button does not respond to the click. And there is no any reaction reaction to the click.
=====
<ListView ItemsSource="{Binding Records}" >

<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="100" Header="ID" DisplayMemberBinding="{Binding ArticleId}" />
<GridViewColumn Width="100" Header="TITLE" DisplayMemberBinding="{Binding Title}" />
<GridViewColumn Width="100" Header="DECRIPTION" DisplayMemberBinding="{Binding Descripton}" />
<GridViewColumn Width="100" Header="CATEGORY" DisplayMemberBinding="{Binding Category}" />
<GridViewColumn Width="100" Header="AUTHOR" DisplayMemberBinding="{Binding Author}" />
<GridViewColumn Width="100" Header="Actions">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button
Command="{Binding DeleteCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
CommandParameter="{Binding SelectedRecord}"
Content="DELETE" />

</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
======
public class RecordsViewModel : ViewModelBase
private Article _selectedRecord;
public RecordsViewModel()
{
LoadData();
DeleteCommand = new MyCommand((s) => true, Delete);
}
public ICommand DeleteCommand { get; set; }
private void Delete(object obj)
{
var rec = obj as Article;
using (AppDbContext context = new AppDbContext())
{
context.News.Remove(rec);
context.SaveChanges();
}
}
private void LoadData() {
using (AppDbContext context = new AppDbContext())
{

var listRecords = context.News.ToList();
_records = new ObservableCollection<Article>(listRecords);

}
}
private ObservableCollection<Article> _records { get; set; }

public ObservableCollection<Article> Records
{
get { return _records; }
set
{
_records = value;
OnPropertyChanged("CollectionCar");
}
}
=========
class MyCommand : ICommand
{
Action<object> _execute;
Func<object, bool> _canExecute;

public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public MyCommand(Func<object, bool> canExecute , Action<object> execute)
{
_execute = execute;
_canExecute = canExecute;
}

public bool CanExecute(object parameter)
{
// return _canExecute == null || _canExecute(parameter);
return _canExecute != null && _canExecute.Invoke(parameter);
}
public void Execute(object parameter) => _execute?.Invoke(parameter);

======

Ответить
Naga Boosh
Naga Boosh - 17.01.2022 16:42

how to use sql procedures in WPF MVVM concept without using the EnityFramework

Ответить
Zerg Zerg
Zerg Zerg - 07.01.2022 23:47

Pardon, but where is the code of EmployeEntities class? Ist it DbContext realization?

Ответить
Hokkaido Viners
Hokkaido Viners - 30.12.2021 12:57

Thanks for this video but as a beginner can you explain the code behind your application?its so very fast for me..thank you

Ответить
Jeroen Christens/Schreurs
Jeroen Christens/Schreurs - 22.12.2021 09:28

It is not loading? I have a few records in the table.

Ответить
Gerken
Gerken - 22.08.2021 16:00

Source code? this is going to fast for me

Ответить
Miral shah
Miral shah - 20.08.2021 08:45

Excellent :) This Channel will touch million views

Ответить
Naga Boosh
Naga Boosh - 06.07.2021 18:15

Thank you

Ответить
hassan hilaly
hassan hilaly - 01.06.2021 01:26

hello sir, subtitle will be helpfull.

Ответить
hassan hilaly
hassan hilaly - 29.05.2021 20:53

Hello sir, Please how do you auto generate OnPropertyChanged ? thanks in advance.

Ответить
hassan hilaly
hassan hilaly - 29.05.2021 00:04

Thank you very much, it's very helpfull.

Ответить
Azzeddine Dia
Azzeddine Dia - 25.04.2021 15:02

Hello Sir, you are Awesome Nice work, and the same as I was looking for... Such topic like that not easy to find I hope you can keep time to time to do more video in the same context, it will be helpful. Just not make the video so quick 😁😁😁 my eyes was flying... Thank you so much and keep going

Ответить
Nilesh chaudhari
Nilesh chaudhari - 25.04.2021 13:21

Helpful tutorial Thanks 🙌

Ответить
Pawel Pedros
Pawel Pedros - 25.04.2021 10:56

Super tutorial. Please do the same, only from DataGrid. 😃👍👍👍

Ответить