asp.net-core - 如何在我的数据库中使用实体框架核心中定义的函数?
问题描述
我想使用实体框架核心从数据库中获取数据,而不是像此示例中那样使用 sql 请求:
SELECT INT_To_STR(CODE), LIBELLE FROM TABLE2
将替换为:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle(ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Ccy>(entity =>
{
entity.ToTable("Table2");
entity.HasKey(e => e.Code);
entity.Property(e => e.Code).HasColumnName("CODE");
entity.Property(e => e.Name).HasColumnName("LIBELLE");
});
}
我面临的问题是我想使用函数 'INT_To_STR' 有什么解决方案吗?谢谢。
解决方案
请查看查询类型。在他们的帮助下,您可以像这样在数据库中调用用户定义的函数:
context.[QUERYTYPE].FromSql("SELECT [FUNCTIONNAME] ...")
推荐阅读
- react-native - 反应原生:触摸事件传播到堆栈上的前一个屏幕
- javascript - 如何创建端点的持久性加载以触发计划
- node.js - 使用 Heroku 部署 Angular + Node 时出现问题
- node.js - 在打字稿中使用 jest 模拟 postgres 数据库连接(Pool,PoolClient,pg)
- heroku - 使用 create-react-app 时无效的主机头
- oauth-2.0 - 为什么这个范围表示为 URI?
- vue.js - Vue 嵌套转换无法应用预期的类
- node.js - 将 cookie 字符串解析为坚韧的 cookie 容器
- go - Golang-Paho MQTT 订阅者在重新初始化订阅者后不断断开连接并出现错误 EOF
- vba - 从正文中提取电子邮件地址并自动回复