Fluent Create Index in MS SQL with INCLUDED

Thread is closed for posting
2 posts, 0 answers
  1. Guy
    Guy avatar
    4 posts
    Member since:
    Apr 2015

    Posted 02 Mar 2017 Link to this post

    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?

     

     

     

     

  2. Guy
    Guy avatar
    4 posts
    Member since:
    Apr 2015

    Posted 09 Mar 2017 in reply to Guy Link to this post

    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");

     

     

Back to Top