gpt4 book ai didi

c# - 使用表创建 c# 类。 Sqlite网

转载 作者:行者123 更新时间:2023-11-30 17:05:44 27 4
gpt4 key购买 nike

我在 Windows 应用商店应用程序的独立存储中有 SQLite 数据库。我使用 Windows 运行时的 SQLite

我的类(class):

[Table("Projects")]
public class Project
{
[PrimaryKey]
[Column ("id")]
public int Id { get; set; }

[Column("group_id")]
public int GroupId { get; set; }

public string Name { get; set; }
}

我从网络服务器获取数据并将其放入本地 DataBase。当我尝试将数据存储到 DataBase 时,我处理了异常

 e.message = table Projects has no column named Name 

因为 DataBase 没有“Name”列

我的问题是:如何使用一个带有字段的类,映射到DataBase Column 和简单的字段? (我不会在 DataBase 中包含一些字段,但我在类里面需要它。)

UPD。

using System.ComponentModel.DataAnnotations.Schema;

[NotMapped]
public string Name { get; set; }

Error The type or namespace name 'NotMappedAttribute' does not exist in the namespace 'System.ComponentModel.DataAnnotations.Schema' (are you missing an assembly reference?)

当我尝试添加 System.ComponentModel.DataAnnotations.dll 错误:无法添加 System.ComponentModel.DataAnnotations.dll。该组件已被构建系统自动引用

最佳答案

看来您正在使用 sqlite-net在这种情况下,您需要使用 SQLite.IgnoreAttribute

[SQLite.Ignore]
public string Name { get; set; }

关于c# - 使用表创建 c# 类。 Sqlite网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16146306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com