EnitityFramework is very slow to compare strings because create a nvarchar sqlparameter instead of varchar

后端 未结 3 1371
别跟我提以往
别跟我提以往 2020-12-11 23:55

I have this sample query:

context.BarcodeTipiDoc.AsQueryable().Where(d => d.Barcode.CompareTo(minBarcode) > 0);
         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 00:40

    In your column mapping, you originally declared this:

    [Column("Barcode", TypeName = "varchar(21)")]   
    public string Barcode { get; set; }
    

    Can you try this:

    [Column(TypeName = "VARCHAR(21)")]
    public string Barcode { get; set; }
    

    Or you can specify in the Model Builder:

    modelBuilder.Entity()
                .Property(x=> x.BarCode)
                .HasColumnType("varchar(21)");
    

    It would also help if you could post the model for your object BarcodeTipiDoc.

    Update: Just saw that you were using EF Core.

提交回复
热议问题