简体   繁体   中英

Entity Framework Convert String to Int

In my where clause of a query I am trying to compare a column with a type of varchar, which contains numbers, to a predetermined integer. I want the ones that are greater than the predetermined number.

From what I've researched it's not possible to do this, as the standard functions are not available in SQL.

Can anyone suggest a way I can do this?

The line in *** is where I am trying to do the comparison. SVNREVISION is the string storing numeric characters.

.Where(
    @t =>
    @t.@t.@t.@t.a.MAINTBRANCH == 197 && @t.e.FIELDID == 106011301 ***&& @t.@t.@t.@t.a.SVNREVISION > 42544***
    && (@t.@t.@t.@t.a.CSEBRANCHCHANGE ?? "") != ""
    && !(@t.@t.@t.@t.a.CSEBRANCHCHANGE ?? "").Contains("DF"))
.Select(
    @t =>

Unfortunately it's not possible for me to change the data type of SVNREVISION.

You'll have to do the filtering in memory instead of converting it into a SQL statement. You do it by forcing Entity Framework to evaluate the expression before you invoke the Where method by adding ToList() :

.ToList()
.Where(
    @t =>
    @t.@t.@t.@t.a.MAINTBRANCH == 197 && @t.e.FIELDID == 106011301 && Convert.ToInt32(@t.@t.@t.@t.a.SVNREVISION) > 42544
    && (@t.@t.@t.@t.a.CSEBRANCHCHANGE ?? "") != ""
    && !(@t.@t.@t.@t.a.CSEBRANCHCHANGE ?? "").Contains("DF"))
.Select(
    @t =>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM