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:
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as “” or [] are not allowed. Change the alias to a valid name.
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.