|
@@ -1,7 +1,6 @@
|
|
using Vitorm.Sql;
|
|
using Vitorm.Sql;
|
|
using Vit.Extensions;
|
|
using Vit.Extensions;
|
|
using Vit.Core.Util.ConfigurationManager;
|
|
using Vit.Core.Util.ConfigurationManager;
|
|
-using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
|
namespace Vitorm.MsTest
|
|
namespace Vitorm.MsTest
|
|
{
|
|
{
|
|
@@ -9,21 +8,24 @@ namespace Vitorm.MsTest
|
|
public class User
|
|
public class User
|
|
{
|
|
{
|
|
[System.ComponentModel.DataAnnotations.Key]
|
|
[System.ComponentModel.DataAnnotations.Key]
|
|
- [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
|
|
- [System.ComponentModel.DataAnnotations.Schema.Column("id", TypeName = "int")]
|
|
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userId", TypeName = "int")]
|
|
public int id { get; set; }
|
|
public int id { get; set; }
|
|
|
|
|
|
- [System.ComponentModel.DataAnnotations.Schema.Column("name", TypeName = "varchar(1000)")]
|
|
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userName", TypeName = "varchar(1000)")]
|
|
[System.ComponentModel.DataAnnotations.Required]
|
|
[System.ComponentModel.DataAnnotations.Required]
|
|
public string name { get; set; }
|
|
public string name { get; set; }
|
|
-
|
|
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userBirth")]
|
|
public DateTime? birth { get; set; }
|
|
public DateTime? birth { get; set; }
|
|
-
|
|
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userFatherId")]
|
|
public int? fatherId { get; set; }
|
|
public int? fatherId { get; set; }
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userMotherId")]
|
|
public int? motherId { get; set; }
|
|
public int? motherId { get; set; }
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("userClassId")]
|
|
|
|
+ public int? classId { get; set; }
|
|
|
|
|
|
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
|
|
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
|
|
- public string test{ get; set; }
|
|
|
|
|
|
+ public string test { get; set; }
|
|
|
|
|
|
public static User NewUser(int id, bool forAdd = false) => new User { id = forAdd ? 0 : id, name = "testUser" + id };
|
|
public static User NewUser(int id, bool forAdd = false) => new User { id = forAdd ? 0 : id, name = "testUser" + id };
|
|
|
|
|
|
@@ -33,6 +35,22 @@ namespace Vitorm.MsTest
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Table("UserClass")]
|
|
|
|
+ public class UserClass
|
|
|
|
+ {
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Key]
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("classId")]
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
|
|
|
|
+ public int id { get; set; }
|
|
|
|
+ [System.ComponentModel.DataAnnotations.Schema.Column("className")]
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+
|
|
|
|
+ public static List<UserClass> NewClasses(int startId, int count = 1)
|
|
|
|
+ {
|
|
|
|
+ return Enumerable.Range(startId, count).Select(id => new UserClass { id = 0, name = "class" + id }).ToList();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
public class DataSource
|
|
public class DataSource
|
|
{
|
|
{
|
|
@@ -49,11 +67,13 @@ namespace Vitorm.MsTest
|
|
|
|
|
|
dbContext.BeginTransaction();
|
|
dbContext.BeginTransaction();
|
|
|
|
|
|
- dbContext.Execute(sql: "IF OBJECT_ID(N'User', N'U') IS NOT NULL \r\nDROP TABLE [User];");
|
|
|
|
|
|
+ #region #1 init User
|
|
|
|
+ {
|
|
|
|
+ dbContext.Execute(sql: "IF OBJECT_ID(N'User', N'U') IS NOT NULL \r\nDROP TABLE [User];");
|
|
|
|
|
|
- dbContext.Create<User>();
|
|
|
|
|
|
+ dbContext.Create<User>();
|
|
|
|
|
|
- var users = new List<User> {
|
|
|
|
|
|
+ var users = new List<User> {
|
|
new User { name="u146", fatherId=4, motherId=6 },
|
|
new User { name="u146", fatherId=4, motherId=6 },
|
|
new User { name="u246", fatherId=4, motherId=6 },
|
|
new User { name="u246", fatherId=4, motherId=6 },
|
|
new User { name="u356", fatherId=5, motherId=6 },
|
|
new User { name="u356", fatherId=5, motherId=6 },
|
|
@@ -62,11 +82,26 @@ namespace Vitorm.MsTest
|
|
new User { name="u600" },
|
|
new User { name="u600" },
|
|
};
|
|
};
|
|
|
|
|
|
- dbContext.AddRange(users);
|
|
|
|
|
|
+ dbContext.AddRange(users);
|
|
|
|
+
|
|
|
|
+ users.ForEach(user =>
|
|
|
|
+ {
|
|
|
|
+ user.birth = DateTime.Parse("2021-01-01 00:00:00").AddHours(user.id);
|
|
|
|
+ user.classId = user.id % 2 + 1;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ dbContext.UpdateRange(users);
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
|
|
- users.ForEach(user => { user.birth = DateTime.Parse("2021-01-01 00:00:00").AddHours(user.id); });
|
|
|
|
|
|
+ #region #2 init Class
|
|
|
|
+ {
|
|
|
|
+ dbContext.Execute(sql: "IF OBJECT_ID(N'UserClass', N'U') IS NOT NULL \r\nDROP TABLE [UserClass];");
|
|
|
|
|
|
- dbContext.UpdateRange(users);
|
|
|
|
|
|
+ dbContext.Create<UserClass>();
|
|
|
|
+ dbContext.AddRange(UserClass.NewClasses(1, 6));
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
|
|
return dbContext;
|
|
return dbContext;
|
|
}
|
|
}
|