Concat Max Value to an int32 using Linq
up vote
0
down vote
favorite
I'm new in using Linq and I'm having a problem on how to Concat a max value in my database to be used as unique attribute using linq. I have found a solution but it is written in SQL query
(select ISNULL(MAX(PersonID + 1), 100000) as nn from Persons)
and tried it and the max personId is 80 so the output becomes 100081
Thanks
EDIT: so i stand corrected, it only acts as Case, sorry guys i feel so dumb :(
c# sql linq
|
show 5 more comments
up vote
0
down vote
favorite
I'm new in using Linq and I'm having a problem on how to Concat a max value in my database to be used as unique attribute using linq. I have found a solution but it is written in SQL query
(select ISNULL(MAX(PersonID + 1), 100000) as nn from Persons)
and tried it and the max personId is 80 so the output becomes 100081
Thanks
EDIT: so i stand corrected, it only acts as Case, sorry guys i feel so dumb :(
c# sql linq
If the maxpersonId
is80
, from this query it will return81
. Also I don't understand100000
part, why you would set to100000
if yourid
does not exist in that table?
– SeM
Nov 22 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 at 6:45
1
Where do you seeConcat
here? It will check ifPersonId
is null then it willSELECT 100000
if it is not -MAX(PersonID + 1)
.
– SeM
Nov 22 at 6:47
could you run this command and check output(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
1
@EnriqueGil It is the same with:var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new in using Linq and I'm having a problem on how to Concat a max value in my database to be used as unique attribute using linq. I have found a solution but it is written in SQL query
(select ISNULL(MAX(PersonID + 1), 100000) as nn from Persons)
and tried it and the max personId is 80 so the output becomes 100081
Thanks
EDIT: so i stand corrected, it only acts as Case, sorry guys i feel so dumb :(
c# sql linq
I'm new in using Linq and I'm having a problem on how to Concat a max value in my database to be used as unique attribute using linq. I have found a solution but it is written in SQL query
(select ISNULL(MAX(PersonID + 1), 100000) as nn from Persons)
and tried it and the max personId is 80 so the output becomes 100081
Thanks
EDIT: so i stand corrected, it only acts as Case, sorry guys i feel so dumb :(
c# sql linq
c# sql linq
edited Nov 22 at 6:57
asked Nov 22 at 6:38
Enrique Gil
36021135
36021135
If the maxpersonId
is80
, from this query it will return81
. Also I don't understand100000
part, why you would set to100000
if yourid
does not exist in that table?
– SeM
Nov 22 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 at 6:45
1
Where do you seeConcat
here? It will check ifPersonId
is null then it willSELECT 100000
if it is not -MAX(PersonID + 1)
.
– SeM
Nov 22 at 6:47
could you run this command and check output(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
1
@EnriqueGil It is the same with:var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28
|
show 5 more comments
If the maxpersonId
is80
, from this query it will return81
. Also I don't understand100000
part, why you would set to100000
if yourid
does not exist in that table?
– SeM
Nov 22 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 at 6:45
1
Where do you seeConcat
here? It will check ifPersonId
is null then it willSELECT 100000
if it is not -MAX(PersonID + 1)
.
– SeM
Nov 22 at 6:47
could you run this command and check output(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
1
@EnriqueGil It is the same with:var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28
If the max
personId
is 80
, from this query it will return 81
. Also I don't understand 100000
part, why you would set to 100000
if your id
does not exist in that table?– SeM
Nov 22 at 6:43
If the max
personId
is 80
, from this query it will return 81
. Also I don't understand 100000
part, why you would set to 100000
if your id
does not exist in that table?– SeM
Nov 22 at 6:43
@SeM no sir it will return
100081
because of the 100000
that is being concat– Enrique Gil
Nov 22 at 6:45
@SeM no sir it will return
100081
because of the 100000
that is being concat– Enrique Gil
Nov 22 at 6:45
1
1
Where do you see
Concat
here? It will check if PersonId
is null then it will SELECT 100000
if it is not - MAX(PersonID + 1)
.– SeM
Nov 22 at 6:47
Where do you see
Concat
here? It will check if PersonId
is null then it will SELECT 100000
if it is not - MAX(PersonID + 1)
.– SeM
Nov 22 at 6:47
could you run this command and check output
(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
could you run this command and check output
(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
1
1
@EnriqueGil It is the same with:
var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28
@EnriqueGil It is the same with:
var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425158%2fconcat-max-value-to-an-int32-using-linq%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If the max
personId
is80
, from this query it will return81
. Also I don't understand100000
part, why you would set to100000
if yourid
does not exist in that table?– SeM
Nov 22 at 6:43
@SeM no sir it will return
100081
because of the100000
that is being concat– Enrique Gil
Nov 22 at 6:45
1
Where do you see
Concat
here? It will check ifPersonId
is null then it willSELECT 100000
if it is not -MAX(PersonID + 1)
.– SeM
Nov 22 at 6:47
could you run this command and check output
(select ISNULL(MAX(PersonID + 1), 999999999) as nn from Persons)
– Ehsan.Saradar
Nov 22 at 6:47
1
@EnriqueGil It is the same with:
var maxId = context.Persons.Max(p => (int?)p.PersonID); maxId = maxId != null ? maxId+1 : 100000;
– SeM
Nov 22 at 7:28