This is a migrated thread and some comments may be shown as answers.

Fluent Create Index in MS SQL with INCLUDED

1 Answer 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Guy
Top achievements
Rank 1
Guy asked on 02 Mar 2017, 08:16 PM

I have an index in a table that looks like this.

CREATE NONCLUSTERED INDEX [idx_RouteAssignment_Dashboard] ON [dbo].[RouteAssignments]
(
[VehicleId] ASC,
[ActualPullOutTime] ASC,
[ActualPullInTime] ASC
)
INCLUDE ( [RouteId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

This configuration will create index, but I can find no way to include the [RouteId] as an INCLUDE.

configuration.HasIndex().WithColumn("VehicleId").Ascending().WithColumn("ActualPullOutTime").Ascending().WithColumn("ActualPullInTime").Ascending().IsNotUnique().WithName("idx_RouteAssignment_Dashboard");

 

If I was to update the schema Data ACcess will delet my current index and put in the on without the INCLUDE.  How do I incorporate the Include or fix the Update DDL?

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Guy
Top achievements
Rank 1
answered on 09 Mar 2017, 07:09 PM

Justs added the lines to a string to add to the end of the script to add the Inlcude to the index when DB is Created.

constraintsDdl.AppendLine("\r");                constraintsDdl.AppendLine("CREATE NONCLUSTERED INDEX [idx_RouteAssignment_Dashboard] ON [dbo].[RouteAssignments]\r");                constraintsDdl.AppendLine("(\r");                constraintsDdl.AppendLine("[VehicleId] ASC,\r");                constraintsDdl.AppendLine("[ActualPullOutTime] ASC,\r");                constraintsDdl.AppendLine("[ActualPullInTime] ASC\r");                constraintsDdl.AppendLine(")\r");                constraintsDdl.AppendLine("INCLUDE (  [RouteId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, WITH(DROP_EXISTING = ON) ON [PRIMARY]");                constraintsDdl.AppendLine();                constraintsDdl.AppendLine("go");                constraintsDdl.AppendLine("\r");

 

 

Tags
General Discussions
Asked by
Guy
Top achievements
Rank 1
Answers by
Guy
Top achievements
Rank 1
Share this question
or