I’m working on a NestJS project where I need to interact with a SQL Server database. One of the tables in the database has a name with dots, specifically dbo.Bonos.Bonos. I’m using TypeORM to manage the database interactions, and I’m encountering issues when trying to query this table.
When I attempt to perform any operations on the table dbo.Bonos.Bonos using TypeORM, I get the following error:
Error: Invalid object name ‘dbo.Bonos.Bonos ‘.”
It seems that TypeORM has trouble handling table names with dots. Here is how I have defined my entity:
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity({ schema: 'dbo', name: 'Bonos.Bonos' }) // **** IMPORTANT: Define the table and schema name ****
export class BonosEntity {
@PrimaryGeneratedColumn()
idBono: number;
@Column()
codigo: string;
@Column()
promocionId: string;
@Column()
NIF: string;
@Column()
CUPS: string;
@Column()
habilitado: number;
@Column({ type: 'date' })
fechaInicio: Date;
@Column({ type: 'date' })
fechaFin: Date;
@Column({ type: 'date' })
fechaUso: Date;
@Column()
importe: number;
}
Pablo Álvarez Relat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4