- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 MariaDB 中的表定义的多对多关系。我正在尝试将 Entity Framework Core 中的导航属性用于相关实体,但它们没有水合。roles
| role_id | role_name |
| 1 | Role-A |
| 2 | Role-B |
groups
| group_id | group_name |
| 1 | Group-A |
| 2 | Group-B |
role_to_group
| role_to_group_id | role_id | group_id |
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | 2 | 2 |
[Table(name: "role_to_group")]
public class RoleToGroup
{
[Column(name: "role_to_group_id")]
public long RoleToGroupId { get; set; }
[Column(name: "role_id")]
[ForeignKey("RGToRoles")]
public int RoleId { get; set; }
[Column(name: "group_id")]
public int UserGroupId { get; set; }
[Include]
public Role Role { get; set; }
[Include]
public UserGroup UserGroup { get; set; }
}
[Include]
是一个自定义属性,用于使用类似于
DbContext.Set().Include("property_name")
的模式来补充导航属性。通过对
T
进行反射的扩展方法并查找所有具有属性
[Include]
的属性在他们身上定义。
Role
Và
UserGroup
返回空值。
1 Câu trả lời
问题可能是 EF Core 不会自动执行延迟加载。 (Documentation about how to implement lazy loading).
安装这些 NuGet 包时:
public class MyDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL(@"User Id=root;Host=localhost;Database=Test;");
optionsBuilder
.UseLazyLoadingProxies();
}
public DbSet UserGroups { get; set; }
public DbSet Roles { get; set; }
public DbSet RoleToGroups { get; set; }
}
using (var context = new MyDbContext())
{
var roleGroup1 = context.RoleToGroups.First();
Console.WriteLine(roleGroup1.Role.Name); //Role-A
Console.WriteLine(roleGroup1.UserGroup.Name); //Group-A
}
[Table(name: "role_to_group")]
public class RoleToGroup
{
[Column(name: "role_to_group_id")]
public int RoleToGroupId { get; set; }
[Column(name: "role_id")]
[ForeignKey("roles")]
public int RoleId { get; set; }
[Column(name: "group_id")]
[ForeignKey("groups")]
public int UserGroupId { get; set; }
public virtual Role Role { get; set; } //must be virtual
public virtual UserGroup UserGroup { get; set; }//must be virtual
}
[Table(name: "roles")]
public class Role
{
[Key]
[Column(name: "role_id")]
public int RoleId { get; set; }
[Column(name: "role_name")]
public string Name { get; set; }
}
[Table(name: "groups")]
public class UserGroup
{
[Key]
[Column(name: "group_id")]
public int GroupId { get; set; }
[Column(name: "group_name")]
public string Name { get; set; }
}
关于mariadb - Entity Framework Core + MariaDB - 导航属性为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56124947/
我在 CentOS 6.4 上运行 MariaDB (10.0.2-MariaDB) 并且想使用 MariaDB 的 CONNECT-Engine 从一些日志文件中读取。由于日志文件很大,我用两个 C
MariaDB 是否支持嵌套事务(不是保存点)? 我希望能够在存储过程中使用嵌套事务。目前在 MySQL 中,我将一个参数“useTransaction”传递给每个存储过程,它控制我是否在该存储过程的
MariaDb 的默认端口是什么? 我是编程新手。我正在创建我的第一个连接到 MariaDB 的 Java 应用程序。我需要指定数据库端口。 最佳答案 Mariadb 的默认端口是 3306。 它与
ubuntu:~$ sudo apt-get install mariadb-server Reading package lists... Done Building dependency tr
我在Ubuntu 18.04上使用的是Mariadb 10.4.10,工具客户端是DBeaver 6.2.5 我想充分利用 Mariadb 中的约束检查功能来确保数据完整性,因为它是从 10.2.1
当我在 phpmyadmin 中运行这个 sql 时 SELECT @@SQL_MODE, @@GLOBAL.SQL_MODE; 表明 @@SQL_MODE STRICT_TRANS_TABLES,E
我正在尝试使用 MariaDB 10.1.12 的联合引擎来创建基于远程数据库中的表的表。关注MariaDB instructions关于如何使用 FederatedX 实现,在数据库 db1 中我创
我在该数据库中有此列,其中包含空格键,我想更改它。 ALTER TABLE . CHANGE COLUMN `Anzahl Personen` AnzahlPersonen int(11); 在命令行
我正在尝试安装 maria db 并遇到以下问题。 [root@localhost ~]# service mysqld start Redirecting to /bin/systemctl sta
我已经基于 mariadb:10.1 构建了一个图像这基本上添加了一个新的 cluster.conf但是在第一个节点开始成功工作后,在第二个节点上面临以下错误。有人可以帮我在这里调试吗? 错误日志尾部
我已阅读 the docs用于 MariaDB REGEX_REPLACE但无法让我的查询工作。我将链接存储在一列中,link并想更改链接的结尾: 来自 www.example.com/至 www.e
我在 MariaDB 的 ColumnStore 上发现的每一项分析都声称它使用的磁盘空间比 InnoDB 等常规引擎少,例如:https://www.percona.com/blog/2017/03
如何在 MariaDB 中重置密码?我使用 Windows 而不是 Linux。谁知道如何重置我的 MySQL MariaDB 密码?我尝试在 Google 上搜索但没有帮助。 最佳答案 我遇到了同样
我正在尝试将 Quarkus 与 MariaDB 图像一起用于测试。 使用 mvn integration-test 启动测试时,我得到以下信息: Unable to start devservice
我正在尝试更新存储在 MariaDB 的 json 列中的数据(libmysql 版本 - 5.6.43,服务器:10.3.34-MariaDB-cll-lve - MariaDB 服务器)。 我的数
我有一个使用 MariaDB 中的表定义的多对多关系。我正在尝试将 Entity Framework Core 中的导航属性用于相关实体,但它们没有水合。 roles | role_id | role
Entity Framework Core 是否支持 MariaDB? 我看到它不在 supported providers 的列表中,但 MySQL 是。也许 MySQL 提供程序会针对 Maria
我在 MariaDb (10.4.10-MariaDB-1:10.4.10+maria~bionic) 中有一个巨大的表,我正在使用添加一个新列 alter table Appointment add
有没有一种方法可以监听 MySQL/MariaDB 中的数据库更改,就像您可以跟踪 MongoDB oplog 一样?我在网上找不到关于此的信息。也许它只适用于 Postgres 而不适用于 MySQ
我刚刚在 Centos 7 中安装了 MariaDB 10.3 数据库服务器。 一切顺利,但在执行“systemctl status mariadb”命令时。这是完整的输出: root@vps [/e
Tôi là một lập trình viên xuất sắc, rất giỏi!