TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Flenner Tom
NA
9
516
Problem with Many to Many and EF6
Mar 28 2019 3:53 PM
Hello guys!
I have some trouble with EF6 using MySql database and a many to many relation with an association table.
So i have these entities :
[Table(
"user"
)]
public
partial
class
user
{
public
user()
{
}
public
int
id {
get
;
set
; }
[Required]
[StringLength(255)]
public
string
first_name {
get
;
set
; }
[Required]
[StringLength(255)]
public
string
last_name {
get
;
set
; }
[Required]
[StringLength(255)]
public
string
email {
get
;
set
; }
[Required]
[StringLength(255)]
public
string
hash {
get
;
set
; }
public
virtual
ICollection<role> Roles {
get
;
set
; }
[Table(
"role"
)]
public
partial
class
role
{
public
role()
{
}
public
int
id {
get
;
set
; }
[Required]
[StringLength(255)]
public
string
title {
get
;
set
; }
public
virtual
ICollection<user> Users {
get
;
set
; }
}
And i start like that : i enable migrations, its working perfectly. I add first migration, its working perfectly.
But when i try to update-database i have this error :
System.FormatException : Input string was not in a correct format.
But i dont know why, because when i delete the collection in the 2 entities it work perfectly..
There is my context :
public
class
TestContext : DbContext
{
public
TestContext() :
base
(
"name=TestContext"
)
{
Database.SetInitializer<TestContext>(
new
DropCreateDatabaseIfModelChanges<TestContext>());
}
public
virtual
DbSet<role> Roles {
get
;
set
; }
public
virtual
DbSet<user> Users {
get
;
set
; }
protected
override
void
OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<user>()
.HasMany(e => e.Roles)
.WithMany(e => e.Users)
.Map(m => m.ToTable(
"role_user"
,
"test"
));
}
Someone have idea ?
Thank you!
Reply
Answers (
5
)
How to show image for 10 second period then will be null aft
how to edit json in c#