Concat Max Value to an int32 using 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
|
show 5 more comments
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 '18 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 '18 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 '18 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 '18 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 '18 at 7:28
|
show 5 more comments
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 '18 at 6:57
Enrique Gil
asked Nov 22 '18 at 6:38
Enrique GilEnrique Gil
36521235
36521235
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 '18 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 '18 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 '18 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 '18 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 '18 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 '18 at 6:43
@SeM no sir it will return100081
because of the100000
that is being concat
– Enrique Gil
Nov 22 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 6:43
@SeM no sir it will return
100081
because of the 100000
that is being concat– Enrique Gil
Nov 22 '18 at 6:45
@SeM no sir it will return
100081
because of the 100000
that is being concat– Enrique Gil
Nov 22 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 7:28
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
0
active
oldest
votes
0
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.
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 '18 at 6:43
@SeM no sir it will return
100081
because of the100000
that is being concat– Enrique Gil
Nov 22 '18 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 '18 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 '18 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 '18 at 7:28