Click here to Skip to main content
15,388,805 members
Home / Discussions / C#
   

C#

 
GeneralRe: JSDOC '@extends' is not attached to class Pin
Luis M. Rojas4-Jul-22 5:18
MemberLuis M. Rojas4-Jul-22 5:18 
GeneralRe: JSDOC '@extends' is not attached to class Pin
Pete O'Hanlon4-Jul-22 19:55
mvaPete O'Hanlon4-Jul-22 19:55 
GeneralRe: JSDOC '@extends' is not attached to class Pin
Luis M. Rojas5-Jul-22 2:33
MemberLuis M. Rojas5-Jul-22 2:33 
AnswerRe: JSDOC '@extends' is not attached to class Pin
Richard MacCutchan4-Jul-22 5:49
mveRichard MacCutchan4-Jul-22 5:49 
QuestionVisual Studio Web Performance and Load Testing Tools alternative Pin
j11codep3-Jul-22 23:11
Memberj11codep3-Jul-22 23:11 
AnswerRe: Visual Studio Web Performance and Load Testing Tools alternative Pin
Pete O'Hanlon3-Jul-22 23:54
mvaPete O'Hanlon3-Jul-22 23:54 
GeneralRe: Visual Studio Web Performance and Load Testing Tools alternative Pin
j11codep4-Jul-22 0:18
Memberj11codep4-Jul-22 0:18 
QuestionLinq to SQL With Enum On Null Field [MODIFIED] Pin
Kevin Marois1-Jul-22 17:49
professionalKevin Marois1-Jul-22 17:49 
I have a table that store person data. There are NamePrefix and NameSuffix columns in the data. Both are nullable.

Here is the Persons table
CREATE TABLE [dbo].[Persons]
(
    Id                          INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
    RemoteId                    UNIQUEIDENTIFIER NOT NULL,
    ClientRepId                 INT NULL FOREIGN KEY (ClientRepId) REFERENCES Persons(Id),
    SupervisorId                INT NULL FOREIGN KEY (SupervisorId) REFERENCES Persons(Id),
    PersonType                  INT NOT NULL,
    Prefix                      INT NULL,
    FirstName                   VARCHAR(MAX),
    LastName                    VARCHAR(MAX),
    NickName                    VARCHAR(MAX),
    Suffix                      INT NULL,
    Title                       VARCHAR(MAX)
)
Here is the PersonEntity
namespace CLOI.Entities
{
    public class PersonEntity : _EntityBase
    {
        private PersonType _PersonType;
        public PersonType PersonType
        {
            get { return _PersonType; }
            set
            {
                SetProperty<PersonType>("PersonType", ref _PersonType, value);
            }
        }

        private NamePrefix _Prefix;
        public NamePrefix Prefix
        {
            get { return _Prefix; }
            set
            {
                SetProperty<NamePrefix>("Prefix", ref _Prefix, value);
            }
        }

        private string _FirstName;
        public string FirstName
        {
            get { return _FirstName; }
            set
            {
                SetProperty<string>("FirstName", ref _FirstName, value);
            }
        }

        private string _LastName;
        public string LastName
        {
            get { return _LastName; }
            set
            {
                SetProperty<string>("LastName", ref _LastName, value);
            }
        }

        private string _NickName;
        public string NickName
        {
            get { return _NickName; }
            set
            {
                SetProperty<string>("NickName", ref _NickName, value);
            }
        }

        private NameSuffix _Suffix;
        public NameSuffix Suffix
        {
            get { return _Suffix; }
            set
            {
                SetProperty<NameSuffix>("Suffix", ref _Suffix, value);
            }
        }

        private string _Title;
        public string Title
        {
            get { return _Title; }
            set
            {
                SetProperty<string>("Title", ref _Title, value);
            }
        }

        public string FullName
        {
            get { return $"{FirstName} {LastName}"; }
        }

        private int _ClientRepId;
        public int ClientRepId
        {
            get { return _ClientRepId; }
            set
            {
                SetProperty<int>("ClientRepId", ref _ClientRepId, value);
            }
        }
    }
}

I'm trying to get this to work:
results = (from p in dc.Persons
            select new PersonEntity
            {
                RemoteId = p.RemoteId,
                ClientRepId = p.ClientRepId ?? 0,
                SupervisorId = p.SupervisorId ?? 0,
                PersonType = (PersonType)p.PersonType ?? PersonType.None,
                Prefix = (NamePrefix)p.Prefix ?? NamePrefix.None,
                FirstName = p.FirstName,
                LastName = p.LastName,
                NickName = p.NickName,
                Suffix = (NameSuffix)p.Suffix ?? NameSuffix.None,
                Title = p.Title,
                CreatedById = p.CreatedById,
                CreatedDT = p.CreatedDT,
                LastModifiedById = p.Id,
                LastModifiedDT = p.ModifiedByDT.Value,
                DeletedById = p.DeletedById,
                DeletedDT = p.DeletedByDT.Value
            }).Where(predicate).ToList();
It's throwing a null ref exception because both the NamePrefix and NameSuffix columns are null.

I tried to change those lines like this:
Prefix = (NamePrefix)p.Prefix ?? NamePrefix.None,

But that won't compile with "
Operator '??' cannot be applied to operands of type 'PersonType' and 'PersonType'
"

What's the right way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.


modified 2-Jul-22 15:40pm.

AnswerRe: Linq to SQL With Enum On Null Field Pin
OriginalGriff1-Jul-22 18:43
mveOriginalGriff1-Jul-22 18:43 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:40
professionalKevin Marois2-Jul-22 9:40 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Dave Kreskowiak2-Jul-22 9:49
mveDave Kreskowiak2-Jul-22 9:49 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:59
professionalKevin Marois2-Jul-22 9:59 
GeneralRe: Linq to SQL With Enum On Null Field Pin
OriginalGriff2-Jul-22 9:52
mveOriginalGriff2-Jul-22 9:52 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:59
professionalKevin Marois2-Jul-22 9:59 
QuestionRe: Linq to SQL With Enum On Null Field Pin
Eddy Vluggen2-Jul-22 10:37
professionalEddy Vluggen2-Jul-22 10:37 
AnswerRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 14:58
professionalKevin Marois2-Jul-22 14:58 
AnswerRe: Linq to SQL With Enum On Null Field Pin
Dave Kreskowiak2-Jul-22 4:59
mveDave Kreskowiak2-Jul-22 4:59 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:43
professionalKevin Marois2-Jul-22 9:43 
AnswerRe: Linq to SQL With Enum On Null Field [MODIFIED] Pin
Richard Deeming4-Jul-22 21:40
mveRichard Deeming4-Jul-22 21:40 
QuestionStreaming data from one datalayer to another Pin
Evilfish200029-Jun-22 4:14
MemberEvilfish200029-Jun-22 4:14 
AnswerRe: Streaming data from one datalayer to another Pin
Pete O'Hanlon29-Jun-22 20:46
mvaPete O'Hanlon29-Jun-22 20:46 
PraiseRe: Streaming data from one datalayer to another Pin
Evilfish200029-Jun-22 21:40
MemberEvilfish200029-Jun-22 21:40 
QuestionC# voice communication between 2 local pcs Pin
Getyourwings UK28-Jun-22 10:07
MemberGetyourwings UK28-Jun-22 10:07 
QuestionIs there anything that Python or Java can do for windows GUI applications while C# can't ? Pin
Code4Ever24-Jun-22 2:33
MemberCode4Ever24-Jun-22 2:33 
AnswerRe: Is there anything that Python or Java can do for windows GUI applications while C# can't ? Pin
Craig Robbins24-Jun-22 6:33
MemberCraig Robbins24-Jun-22 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.