【问题标题】:Is there a way to insert a list of information into another table? in C# codefirst SQLite有没有办法将信息列表插入另一个表?在 C# 代码优先 SQLite
【发布时间】:2021-12-28 05:44:07
【问题描述】:

我想在桌子上记录我的朋友列表。

在我看到的教程中,我们可以给每个朋友拍照。为此,我们创建了一个名为 ImageName 的字符串属性。但是现在我想为每个朋友拍摄不止一张照片,但是这些代码会出错。

    public class Friend
    {
        [PrimaryKey, AutoIncrement]
        public int FriendId { get; set; }

        [NotNull]
        [MaxLength(50)]
        public string FullName { get; set; }

        [NotNull]
        [MaxLength(50)]
        public string Phone { get; set; }

        public List<int> ImageId { get; set; }
    }

    public class FriendImage
    {
        [PrimaryKey, AutoIncrement]
        public int ImageId { get; set; }
        public string ImageName { get; set; }
    }

错误
enter image description here

如果您知道真正的方法,请帮助我。 谢谢
抱歉英语不好。

【问题讨论】:

    标签: c# android sql sqlite xamarin


    【解决方案1】:

    如果您需要存储多张照片,则需要多对多关系以避免重复记录。您必须将其标记为多对多

    [ManyToMany(typeof(FriendImage))]
    public List<int> ImageId { get; set; }
    

    并插入一个列表:

    SQLiteConnection.InsertAll(list_of_FriendImage);
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 2018-07-21
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多