entityframeworktutorial / EF6-DBFirst-Demo

Entity Framework 6 Database-First Demo Project
MIT License
143 stars 159 forks source link

In `DataGridView`, the fields do not match the vault table #1

Closed it19862 closed 5 years ago

it19862 commented 5 years ago

I drag a data source on winform. I get the following composition of the fields. In the DataGridView fields:

Question: how to make the fields in the DataGridView meet the fields in the table? 2019-03-20_20-39-17

[CREATE TABLE [dbo].[tbl_01_Groups] 
(
  [id_group] INT  IDENTITY(1,1) NOT NULL,
  [nameGroup] nvarchar(255) COLLATE Cyrillic_General_CI_AS  NULL,
  [Property_1_Group] nvarchar(255) COLLATE Cyrillic_General_CI_AS  NULL,
  [Property_2_Group] nvarchar(255) COLLATE Cyrillic_General_CI_AS  NULL,
  [Property_3_Group] nvarchar(255) COLLATE Cyrillic_General_CI_AS  NULL,
  CONSTRAINT [PK_tbl_01_Groups] PRIMARY KEY NONCLUSTERED ([id_group])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = OFF)  
ON [PRIMARY]
)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[tbl_01_Groups] SET (LOCK_ESCALATION = TABLE)

CREATE TABLE [dbo].[tbl_03_GroupsStud]
 (
  [id_groupStud] BIGINT  NOT NULL,
  [id_group] INT  NULL,
  [id_stud] BIGINT  NULL,
  [groupStud_descript] nvarchar(255) COLLATE Cyrillic_General_CI_AS  NULL,
  CONSTRAINT [PK_tbl_03_GroupsStud] PRIMARY KEY NONCLUSTERED ([id_groupStud])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = OFF)  
ON [PRIMARY],
  CONSTRAINT [FK_id_grp]
  FOREIGN KEY ([id_group]) 
  REFERENCES [dbo].[tbl_01_Groups] ([id_group]) ON DELETE NO ACTION ON UPDATE NO ACTION
)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[tbl_03_GroupsStud] SET (LOCK_ESCALATION = TABLE)](url)

Context

using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class ContextDBF7 : DbContext
    {
        public ContextDBF7()
            : base("name=ContextDBF7")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<tbl_01_Groups> tbl_01_Groups { get; set; }
        public virtual DbSet<tbl_03_GroupsStud> tbl_03_GroupsStud { get; set; }
    }

using System;
    using System.Collections.Generic;

    public partial class tbl_01_Groups
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public tbl_01_Groups()
        {
            this.tbl_03_GroupsStud = new HashSet<tbl_03_GroupsStud>();
        }

        public int id_group { get; set; }
        public string nameGroup { get; set; }
        public string Property_1_Group { get; set; }
        public string Property_2_Group { get; set; }
        public string Property_3_Group { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<tbl_03_GroupsStud> tbl_03_GroupsStud { get; set; }
    }

using System;
    using System.Collections.Generic;

    public partial class tbl_03_GroupsStud
    {
        public long id_groupStud { get; set; }
        public Nullable<int> id_group { get; set; }
        public Nullable<long> id_stud { get; set; }
        public string groupStud_descript { get; set; }

        public virtual tbl_01_Groups tbl_01_Groups { get; set; }
    }