When making a query how do you check if the default value was returned?

StackOverflow https://stackoverflow.com/questions/23453981

  •  15-07-2023
  •  | 
  •  

문제

Using the code below:

let student =
    query {
        for student in db.Student do
        where (student.StudentID = 1)
        select student
        exactlyOneOrDefault
    }

How do you check the value of student, and just what would be the default value if no match in the database was found?

도움이 되었습니까?

해결책

Database objects come from the database library you're using (either LINQ-to-SQL or Entity Framework), they're not originated from F# so they're nullable. The value returned by exactlyOneOrDefault when there isn't exactly one is null.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top