F
FerrariF70
Guest
class User
{
public int Id { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public UserProfile UserProfile { get; set; }
}
class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public User User { get; set; }
}
[DbConfigurationType(typeof(MySqlEFConfiguration))]
class UserContext : DbContext
{
public UserContext() : base("DefaultConnection") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>().HasRequired(x => x.UserProfile).WithRequiredPrincipal(x => x.User);
}
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<User> Users { get; set; }
}
class Program
{
static void Main(string[] args)
{
static void Main(string[] args)
{
using (UserContext context = new UserContext())
{
var user1 = new User { Login = "user1", Password = "12345" };
var user2 = new User { Login = "user2", Password = "12345" };
var user3 = new User { Login = "user3", Password = "12345" };
context.Users.AddRange(new List<User> { user1, user2, user3 });//here arises exception
context.SaveChanges();
var userProfile1 = new UserProfile { Name = "user1", LastName = "user1LastName", Id = user1.Id };
var userProfile2 = new UserProfile { Name = "user2", LastName = "user1LastName", Id = user2.Id };
var userProfile3 = new UserProfile { Name = "user3", LastName = "user1LastName", Id = user3.Id };
context.UserProfiles.AddRange(new List<UserProfile> { userProfile1, userProfile2, userProfile3 });
context.SaveChanges();
}
}
}
I work through Entity Framework 6 I don’t understand what the trouble was trying in different ways to make a one-to-one relationship, but an exception is constantly thrown System.FormatException: "The input string was in the wrong format.". DBMS MySql. Thanks in advance!
Continue reading...
{
public int Id { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public UserProfile UserProfile { get; set; }
}
class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public User User { get; set; }
}
[DbConfigurationType(typeof(MySqlEFConfiguration))]
class UserContext : DbContext
{
public UserContext() : base("DefaultConnection") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>().HasRequired(x => x.UserProfile).WithRequiredPrincipal(x => x.User);
}
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<User> Users { get; set; }
}
class Program
{
static void Main(string[] args)
{
static void Main(string[] args)
{
using (UserContext context = new UserContext())
{
var user1 = new User { Login = "user1", Password = "12345" };
var user2 = new User { Login = "user2", Password = "12345" };
var user3 = new User { Login = "user3", Password = "12345" };
context.Users.AddRange(new List<User> { user1, user2, user3 });//here arises exception
context.SaveChanges();
var userProfile1 = new UserProfile { Name = "user1", LastName = "user1LastName", Id = user1.Id };
var userProfile2 = new UserProfile { Name = "user2", LastName = "user1LastName", Id = user2.Id };
var userProfile3 = new UserProfile { Name = "user3", LastName = "user1LastName", Id = user3.Id };
context.UserProfiles.AddRange(new List<UserProfile> { userProfile1, userProfile2, userProfile3 });
context.SaveChanges();
}
}
}
I work through Entity Framework 6 I don’t understand what the trouble was trying in different ways to make a one-to-one relationship, but an exception is constantly thrown System.FormatException: "The input string was in the wrong format.". DBMS MySql. Thanks in advance!
Continue reading...