类似于" Coalesce"在实体框架中

时间:2014-03-25 09:25:30

标签: c# sql linq entity-framework

实体框架c#中对以下代码的类似查询是什么。

SELECT StudentId,Coalesce(s.FName + ' ' + s.MName + ' ' + s.LName,
    s.FName + ' ' + s.MName,
    s.FName) AS FullName
FROM Student s
WHERE s.StudentId = 'S101';

提前致谢。

2 个答案:

答案 0 :(得分:3)

查看null-coalescing operator

e.g。

string text1 = null;
string result = text1 == null ? "default" : text1 ;

你可以做到

string result = text1 ?? "default";

答案 1 :(得分:0)

让我说要合并时检查金额,然后使用 Nullable ,如下面的代码示例中所述

typedef struct {
    char **words;
} WordList;

void myFunc(WordList *wordList) {
    ...
    wordList->words = malloc(numberOfWords * sizeof(char *));
    // strSource : this string comes from somewhere in your code
    ...
    for (int i = 0; i < numberOfWords; i++) {
        int numberOfChars = strlen(strSource);
        (wordList->words)[i] = malloc((numberOfChars + 1) * sizeof(char));
        (wordList->words)[i][numberOfChars] = '\0';
        ...
        strcpy((wordList->words)[i], strSource)
        ...
    }
    ...
}

int main() {
    WordList wordList;
    ...
    myFunc(&wordList);
    ...
}