I launch the application.
The application adds and receives entries.
The application adds and receives records to another database, and not to which the connection is made in the code.
I can’t understand what database the application works with.
Category.cs
- //
- using System.Collections.ObjectModel;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- namespace WpfAppFrm
- {
- [Table("Categories")]
- public class Category
- {
- public Category()
- {
- // this.Products = new ObservableCollection
(); - }
- public int CategoryId { get; set; }
- public string Name { get; set; }
- // public virtual ObservableCollection
Products { get; private set; } - }
- }
- //
- using System.Data.Entity;
- namespace WpfAppFrm
- {
- public class ProductContext : DbContext
- {
- // public ProductContext() : base("DefaultConnection")
- public string ConnectionString_test { get; set; }
- public ProductContext(string ?onnectionString)
- {
- this.ConnectionString_test = ?onnectionString;
- }
- public DbSet
Categories { get; set; } - // public DbSet
Products { get; set; } - }
- }
- //
- using System.ComponentModel;
- using System.Data.Entity;
- namespace WpfAppFrm
- {
- ///
- /// ?????? ?????????????? ??? MainWindow.xaml
- ///
- public partial class MainWindow : Window
- {
- // public static string ?onnectionString = @"C:\test\DB\NorthwindC.mdf";
- public static string ?onnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\test\DB\NorthwindC.mdf;Integrated Security=True;Connect Timeout=30";
- // public static string ?onnectionString = @"Data Source=(localdb)\mssqllocaldb;Initial Catalog=WpfAppFrm.ProductContext;Integrated Security=True; MultipleActiveResultSets=True";
- private ProductContext _context = new ProductContext(?onnectionString);
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- try
- {
- System.Windows.Data.CollectionViewSource categoryViewSource =
- ((System.Windows.Data.CollectionViewSource)(this.FindResource("categoryViewSource")));
- _context.Categories.Load();
- BindingList
_studBindList = _context.Categories.Local.ToBindingList(); - categoryViewSource.Source = _context.Categories.Local;
- // AddEntity();
- // GetAll();
- string connectionString_str = _context.Database.Connection.ConnectionString;
- string connectionString_str2 = _context.ConnectionString_test;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- public void AddEntity()
- {
- Category category = new Category
- {
- Name = "Name_Category_4"
- };
- _context.Categories.Add(category);
- _context.SaveChanges();
- }
- public void GetAll()
- {
- _context.Categories.Load();
- BindingList
_studBindList = _context.Categories.Local.ToBindingList(); - }
- }
- }
"WpfAppFrm.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:local="clr-namespace:WpfAppFrm"
- mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="334.874" Loaded="Window_Loaded">
-
-
"categoryViewSource" - d:DesignSource="{d:DesignInstance {x:Type local:Category}, CreateList=True}"/>
-
"categoryProductsViewSource" Source="{Binding Products, Source={StaticResource categoryViewSource}}"/> -
"{StaticResource categoryViewSource}" Margin="0,0,7,0"> -
-
"33*" /> -
"287*" /> -
"0*" /> -
"0*" /> -
"categoryDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" - ItemsSource="{Binding}" Margin="13,13,3,257"
- RowDetailsVisibilityMode="VisibleWhenSelected" Grid.ColumnSpan="2">
-
-
"categoryIdColumn" Binding="{Binding CategoryId}" - Header="CategoryId" Width="SizeToHeader"/>
-
"nameColumn" Binding="{Binding Name}" - Header="Name" Width="SizeToHeader"/>
-
- CREATE TABLE [dbo].[Categories] (
- [CategoryId] INT IDENTITY (1, 1) NOT NULL,
- [Name] NVARCHAR (40) NULL,
- PRIMARY KEY CLUSTERED ([CategoryId] ASC)
Laxmidhar SahooPosted Feb 16, 2020, 12:51 AM
Ivan ClimovPosted Feb 15, 2020, 1:23 AM
Ivan ClimovPosted Feb 15, 2020, 12:43 AM
@Laxmidhar Sahoo
Laxmidhar SahooPosted Feb 15, 2020, 12:01 AM