How to create table in Entity Framework

Posted by Ishan7 under Sql Server on 12/10/2020 | Points: 10 | Views : 308 | Status : [Member] | Replies : 1
My project created in WPF and EntityFramework
I want to create a table in SQL server using Script
Code like this

public override void Up()
{
Execute.Sql(@"CREATE TABLE [dbo].[Exam](
[exam_id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[subject_name] [nvarchar](50) NOT NULL,
[emp_id] [numeric](18, 0) NOT NULL,
[department_id] [numeric](18, 0) NOT NULL,
CONSTRAINT [PK_Exam] PRIMARY KEY CLUSTERED
(
[exam_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO");
}




but not create it.
It throws exception
Exception is:

- InnerException {"The table name is not valid. [ Token line number (if known) = 1,Token line offset (if known) = 22,Table name = Exam ]"} System.Exception {System.Data.SqlServerCe.SqlCeException}

What is the mistake in my code?




Responses

Posted by: Ishan7 on: 2/15/2021 [Member] Starter | Points: 25

Up
0
Down
its look fine, can you please check your connection string?

Ishan7, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response