I have used the above code in MySQL. My table called Currency contains two properties, Unit and Rate but only unit is saving. Rate remains 0. I realize that my BindingSource.Current takes only Unit instead of taking both values.
When I click "Save" on frmAddEditConatct nothing happens... I have revised my code multiple times and it's exactly as in the video. Do you have a link to download the full project?
You can make one video about CRUD Many to Many using EF. Example , I have three table are: Students(StudenID, StudentName); Courses(CourseID, CourseName) and StudentCourse(StudenID,CourseID). Students has many Courses and Courses has many Student. When i design in SQL server, i change many to many equal Students has one to many StudentCourse and Course has one to many StudentCourse=> I have 3 table in sql server. But in visual 2015 i create ado.net ef data created 2 table Students and Courses . linq to sql do not support many to many relationship. I can not create query CRUD join 3 tables. You can help me this problem! thank you so much. Connection String :
Student.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; namespace EFManyToMany { public class Student { [Key] public int StudenID { get; set; } public string StudentName { get; set; } public IList Courses { get; set; } } } Course.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; namespace EFManyToMany { public class Course { [Key] public int CourseID { get; set; } public string CourseName { get; set; } public IList Students { get; set; } } } EmployeeDBContext.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; namespace EFManyToMany { public class EmployeeDBContext: DbContext { public EmployeeDBContext() : base("EmployeeDBContext") { Database.SetInitializer(new MigrateDatabaseToLatestVersion("EmployeeDBContext")); } public DbSet Courses { get; set; } public DbSet Students { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity() .HasMany(t => t.Courses) .WithMany(t => t.Students) .Map(m => { m.ToTable("StudentCourses"); m.MapLeftKey("StudentID"); m.MapRightKey("CourseID"); }); base.OnModelCreating(modelBuilder); } } } Thêm dữ liệu vào các bảng: USE Sample GO INSERT INTO dbo.Courses (CourseName) VALUES ( N'C#') INSERT INTO dbo.Courses (CourseName) VALUES ( N'ASP.NET') INSERT INTO dbo.Courses (CourseName) VALUES ( N'SQL Server') INSERT INTO dbo.Courses (CourseName) VALUES ( N'WCF') INSERT INTO dbo.Students ( StudentName ) VALUES ( N'Mike') INSERT INTO dbo.Students ( StudentName ) VALUES ( N'John') INSERT INTO dbo.StudentCourses VALUES ( N'1', N'1') INSERT INTO dbo.StudentCourses VALUES ( N'1', N'2') INSERT INTO dbo.StudentCourses VALUES ( N'2', N'1') INSERT INTO dbo.StudentCourses VALUES ( N'2', N'2') INSERT INTO dbo.StudentCourses VALUES ( N'2', N'3') Hiển thị dữ liệu: Cách 1: using (EmployeeDBContext context = new EmployeeDBContext()) { dataGridView1.DataSource = (from s in context.Students from c in context.Courses select new { StudentName = s.StudentName, CourseName = c.CourseName }).ToList(); } Kết quả: Cách 2: EmployeeDBContext context = new EmployeeDBContext(); var stu_id = 1; var query = from s in context.Students where s.Courses.Any(c => c.CourseID == stu_id) select s; dataGridView1.DataSource = query.ToList(); Kết quả:
if add one Users table have relationship many Contacts. You show how to CRUD data to two table. thank ! One problem DataAccessLayer includes InterfaceRepository but RepositoryLayer is beetwen DataLayer and BussinessLayer-> project structure is : Model, Repositories, Bussiness and Presentatiion Layer. Link project of fox learn i rebuild www.mediafire.com/file/478ji41wkozc9kc/EF3Tiers.rar
Hey man! what about a video with MySql, Entity Framework, MVVM in WPF and a trivial, step by step example that also the numbskulls among finally understand how to implement the freaking ViewModel. No-one has done this yet, so why don't you give it a try ;)
This is one of the best educational tutorials about n-tier apps on internet. Thanks for uploading!!!
super example on using binding source. more example on binding source please with drop down list, master detail relations pls.
Nice Turorial thx a lot for you support.
Hello fox learn
I want to ask about the display data from more than one table to be used in printing queries
on report viewer
Thank you
Nice video, very useful for new developers.
Thank you so much :)
What is the instrument called 21:12?
very good. thanks for everything
Wonderfull ! Thank you so much for sharing such a knowledge!
NICE
HOW I CAN ADD TO THIS PROJECT A MASTER /DETAIL RELATION ?
thanks
Ok, Thank you for your suggestion. I'll make demo soon
How is the search done here?
Very Nice videos, like your learning style. Could you make more VB.Net videos? It is hard to find good vb videos.
OK. Thank you for your suggestion. I'll make soon
Do you have a lesson where the same principle, but the connection is made through MySqlConnection?
No, I upload soon
Fox Learn ty
Hi, do you have some videos with EF Core and SQLite ? This would be really helpful. Like always great video.
I haven't got, i'll upload soon
Can you do a tutorial about searching using EF - 3Tier ?
i really need it.
Thx btw. This video is very useful
Ok, thank you for your suggestions
th-cam.com/video/Ncbr5axCabM/w-d-xo.html .I uploaded
I have used the above code in MySQL. My table called Currency contains two properties, Unit and Rate but only unit is saving. Rate remains 0. I realize that my BindingSource.Current takes only Unit instead of taking both values.
Bravo!!
Thank you !
Hi. l designed a database, l want to know that, can we save the data in multi tables by clicking on one savebutton?
Yes, You can do that. You can view this video th-cam.com/video/wAfF-MveMIk/w-d-xo.html to know how to do that. Thank you
Could you make a video (Insert, Update,Delete) with Entity Framework and Stored Procedures?
OK. Thank you for your suggestion. I'll make soon
Fox Learn oh thanks :)
Dear sir,,What is code of save button ??
It has no code!
Why?? i ask same, i filled all textboxt in add form then i can't save nothing, what's the code
When I click "Save" on frmAddEditConatct nothing happens... I have revised my code multiple times and it's exactly as in the video. Do you have a link to download the full project?
Please check your code again. i'll upload to my site soon. thank you !
good guide !
Thank you :)
You can make one video about CRUD Many to Many using EF. Example , I have three table are: Students(StudenID, StudentName); Courses(CourseID, CourseName) and StudentCourse(StudenID,CourseID). Students has many Courses and Courses has many Student. When i design in SQL server, i change many to many equal Students has one to many StudentCourse and Course has one to many StudentCourse=> I have 3 table in sql server. But in visual 2015 i create ado.net ef data created 2 table Students and Courses . linq to sql do not support many to many relationship. I can not create query CRUD join 3 tables. You can help me this problem! thank you so much.
Connection String :
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace EFManyToMany
{
public class Student
{
[Key]
public int StudenID { get; set; }
public string StudentName { get; set; }
public IList Courses { get; set; }
}
}
Course.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace EFManyToMany
{
public class Course
{
[Key]
public int CourseID { get; set; }
public string CourseName { get; set; }
public IList Students { get; set; }
}
}
EmployeeDBContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
namespace EFManyToMany
{
public class EmployeeDBContext: DbContext
{
public EmployeeDBContext() : base("EmployeeDBContext")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion("EmployeeDBContext"));
}
public DbSet Courses { get; set; }
public DbSet Students { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasMany(t => t.Courses)
.WithMany(t => t.Students)
.Map(m =>
{
m.ToTable("StudentCourses");
m.MapLeftKey("StudentID");
m.MapRightKey("CourseID");
});
base.OnModelCreating(modelBuilder);
}
}
}
Thêm dữ liệu vào các bảng:
USE Sample
GO
INSERT INTO dbo.Courses (CourseName) VALUES ( N'C#')
INSERT INTO dbo.Courses (CourseName) VALUES ( N'ASP.NET')
INSERT INTO dbo.Courses (CourseName) VALUES ( N'SQL Server')
INSERT INTO dbo.Courses (CourseName) VALUES ( N'WCF')
INSERT INTO dbo.Students ( StudentName ) VALUES ( N'Mike')
INSERT INTO dbo.Students ( StudentName ) VALUES ( N'John')
INSERT INTO dbo.StudentCourses VALUES ( N'1', N'1')
INSERT INTO dbo.StudentCourses VALUES ( N'1', N'2')
INSERT INTO dbo.StudentCourses VALUES ( N'2', N'1')
INSERT INTO dbo.StudentCourses VALUES ( N'2', N'2')
INSERT INTO dbo.StudentCourses VALUES ( N'2', N'3')
Hiển thị dữ liệu:
Cách 1:
using (EmployeeDBContext context = new EmployeeDBContext())
{
dataGridView1.DataSource = (from s in context.Students
from c in context.Courses
select new
{
StudentName = s.StudentName,
CourseName = c.CourseName
}).ToList();
}
Kết quả:
Cách 2:
EmployeeDBContext context = new EmployeeDBContext();
var stu_id = 1;
var query = from s in context.Students
where s.Courses.Any(c => c.CourseID == stu_id)
select s;
dataGridView1.DataSource = query.ToList();
Kết quả:
Hi Again , i can't find a Remove() , Add() ,Entry and Find method , i already add a reference System.data.entity , can you help me please ??
I think you should create a model context, then you can find Add, Remove, Entry... method
Excelent tutorials! Could you send me the project please?
please how find you a references EntityFramwork.SqlServer.dll i can't find it ?! URGENT
Hi, You can install Entity Framework from nuget
can you send me the link please
Is Ok i find it thank u (y)
i like this tut, thank you, more...
can you add the source code link please
just like other channel do ;-)
Hi, What's your email? thank you
artc.jacob@gmail.com
Why don't you make video for separate select update delete and insert buttons operations. You are always creating data grid view with these operations
Thank you for your suggestion
Will be waiting for that
if add one Users table have relationship many Contacts. You show how to CRUD data to two table. thank ! One problem DataAccessLayer includes InterfaceRepository but RepositoryLayer is beetwen DataLayer and BussinessLayer-> project structure is : Model, Repositories, Bussiness and Presentatiion Layer.
Link project of fox learn i rebuild www.mediafire.com/file/478ji41wkozc9kc/EF3Tiers.rar
code pleaes
Sent. Please check your email. Thank you
Hey man! what about a video with MySql, Entity Framework, MVVM in WPF and a trivial, step by step example that also the numbskulls among finally understand how to implement the freaking ViewModel. No-one has done this yet, so why don't you give it a try ;)
Ok. Thank you for your suggestion
Could you make a video (Insert, Update,Delete) with Entity Framework and Code First?
OK. Thank you for your suggestion. I'll make soon
Code Pls