首页 > 解决方案 > 如何在我的数据库中使用实体框架核心中定义的函数?

问题描述

我想使用实体框架核心从数据库中获取数据,而不是像此示例中那样使用 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' 有什么解决方案吗?谢谢。

标签: asp.net-core.net-coreentity-framework-core

解决方案


请查看查询类型。在他们的帮助下,您可以像这样在数据库中调用用户定义的函数:

context.[QUERYTYPE].FromSql("SELECT [FUNCTIONNAME] ...")

推荐阅读