你好,
根据我的研究以及搜索,我重现了您的问题。如果您使用的是EntityFrmework,那么我推荐您的使用EntityFramework-core,这样你可以用下面的方式来存储您的list或者Dictionary对象。
[Table("Fitting")]
public class Fitting
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public double Weight { get; set; }
public virtual Dictionary IceWeightList { get; set; }
}
public class MyContext : DbContext
{
public DbSet Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"connstring");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity().Property(e => e.IceWeightList).HasConversion(v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject>(v));
}
}
在执行完Add-Migration操作后,你会得到:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Fitting",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column(type: "nvarchar(max)", nullable: true),
Weight = table.Column(type: "float", nullable: false),
IceWeightList = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Fitting", x => x.Id);
});
}
注意:完成上面的操作,必须要保证当前的项目是.net core app,还有就是要添加下面的三个nuget 包。
希望能够帮助你。
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.