в моём проекте WPF я использую два способа вывода данных. В 1 способе через SQLite COMMAND и SQLiteDataReader, а во втором через методы расширения Linq. Все данные берутся из SQLite. Какой способ лучше и правильней использовать, подскажите пожалуйста я новичок в WPF. Заранее спасибо!
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<!-- Если не работает, то сделайте следующее. Замените все содержимое файла, но объект startup установите такой же, как был у вас ранее -->
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=D:\C# Project\DrivingApp\DrivingScl.db" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
Здесь я подключаю БД.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SQLite;
namespace DrivingApp
{
/// <summary>
/// Логика взаимодействия для UserPageWIndow.xaml
/// </summary>
public partial class UserPageWIndow : Window
{
private SQLiteConnection DB;
public UserPageWIndow()
{
InitializeComponent();
ApplicationContext db = new ApplicationContext();
DB = new SQLiteConnection("Data Source = DrivingScl.db");
DB.Open();
SQLiteCommand cmd = DB.CreateCommand();
cmd.CommandText = "SELECT id, login FROM Users WHERE id = 3";
SQLiteDataReader SQL = cmd.ExecuteReader();
if (SQL.HasRows)
{
while (SQL.Read() )
{
nam2.Text += "Логин :" + SQL["Login"];
}
}
else nam2.Text = "Нет таких";
var query = db.Users.Where(u => u.id == 3);
foreach (var user in query)
{
nam.Text = "Login " + user.Login;
}
}
}
}
Здесь вывожу логин с id 3 двумя способами в 2 TextBox. Что лучше использовать и вообще профессиональней с точки зрения кода, Если можете пожалуйста развёрнута.
Вот что выводит:
То что вверху это через SqlAdapter, а внизу методы расширения Linq