0

now,i use EF core to search database,with this code

.Select(i => new { id = "" + i.OrganID, name = i.OrganName + "_" + i.LeaderMobile  })

the column named LeaderMobile is nullable, nvarchar(100) null.

when OrganName is not null and LeaderMobile is null, the result is null.

excample:

OrganName="aaa" LeaderMobile =null

The result is null, but I want the result is "aaa_" ( in EF ,it does work)

How can i do without change this code. well, I mean where i can config to make it work.

Not like:

.Select(i => new { id = "" + i.OrganID, name = i.OrganName + "_" + (i.LeaderMobile ?? "") })
4
  • I think you can do this in model class for set of LeaderMobileand assign empty string if this member is null.
    – Vivek Nuna
    Sep 28, 2018 at 4:24
  • @vivek nuna thank you for comment. but this is not i wanted. the database is running. And it has a lot of tables and columns. I want to update my project with transformation as small as possible
    – sdwdjzhy
    Sep 28, 2018 at 5:28
  • you can create an abstract class with this property and inherit the model classes from it.
    – Vivek Nuna
    Sep 28, 2018 at 5:32
  • @vivek nuna Well,maybe i need to get a program to replace the code ?!
    – sdwdjzhy
    Sep 30, 2018 at 0:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.