In Entity Framework id value doesn't get incremented by 1, but by 1000? [duplicate] Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Huge gap in increment value of identity columnGet int value from enum in C#Get property value from string using reflection in C#SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the sessionHow can I get Id of inserted entity in Entity framework?Fastest Way of Inserting in Entity FrameworkEntity Framework TimeoutsEntity Framework Provider type could not be loaded?Entity Framework 5 Updating a RecordHow to update record using Entity Framework 6?Updating Memory Optimized Table
Is there any hidden 'W' sound after 'comment' in : Comment est-elle?
How would this chord from "Rocket Man" be analyzed?
Is a 5 watt UHF/VHF handheld considered QRP?
What is this word supposed to be?
My admission is revoked after accepting the admission offer
How would I use different systems of magic when they are capable of the same effects?
Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?
Function to calculate red-edgeNDVI in Google Earth Engine
Co-worker works way more than he should
Would reducing the reference voltage of an ADC have any effect on accuracy?
Is Electric Central Heating worth it if using Solar Panels?
What's the difference between using dependency injection with a container and using a service locator?
What is it called when you ride around on your front wheel?
What's parked in Mil Moscow helicopter plant?
Passing args from the bash script to the function in the script
Has a Nobel Peace laureate ever been accused of war crimes?
Trumpet valves, lengths, and pitch
Is accepting an invalid credit card number a security issue?
A Paper Record is What I Hamper
What to do with someone that cheated their way through university and a PhD program?
Justification for leaving new position after a short time
Are all CP/M-80 implementations binary compatible?
Israeli soda type drink
The art of proof summarizing. Are there known rules, or is it a purely common sense matter?
In Entity Framework id value doesn't get incremented by 1, but by 1000? [duplicate]
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Huge gap in increment value of identity columnGet int value from enum in C#Get property value from string using reflection in C#SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the sessionHow can I get Id of inserted entity in Entity framework?Fastest Way of Inserting in Entity FrameworkEntity Framework TimeoutsEntity Framework Provider type could not be loaded?Entity Framework 5 Updating a RecordHow to update record using Entity Framework 6?Updating Memory Optimized Table
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
Huge gap in increment value of identity column
2 answers
In the following table, you can see that billid
column is increased by 1000 at 10th row.
The code to generate new bill
is as follows:
private void NewBill()
var bill = new Bill
BillDate = DateTime.Now,
InUse = true,
Paid = false,
TableId = _tableId,
UserId = frmLogIn.LoggedInUserId
;
using (var context = new Context())
context.Bills.Add(bill);
context.SaveChanges();
Why it does not get incremented by just 1 ?
I am using EF6 with SQL Server 2017 Express edition.
c# entity-framework-6
marked as duplicate by CodingYoshi, Lankymart, marc_s
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 9 at 9:21
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Huge gap in increment value of identity column
2 answers
In the following table, you can see that billid
column is increased by 1000 at 10th row.
The code to generate new bill
is as follows:
private void NewBill()
var bill = new Bill
BillDate = DateTime.Now,
InUse = true,
Paid = false,
TableId = _tableId,
UserId = frmLogIn.LoggedInUserId
;
using (var context = new Context())
context.Bills.Add(bill);
context.SaveChanges();
Why it does not get incremented by just 1 ?
I am using EF6 with SQL Server 2017 Express edition.
c# entity-framework-6
marked as duplicate by CodingYoshi, Lankymart, marc_s
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 9 at 9:21
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
4
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27
add a comment |
This question already has an answer here:
Huge gap in increment value of identity column
2 answers
In the following table, you can see that billid
column is increased by 1000 at 10th row.
The code to generate new bill
is as follows:
private void NewBill()
var bill = new Bill
BillDate = DateTime.Now,
InUse = true,
Paid = false,
TableId = _tableId,
UserId = frmLogIn.LoggedInUserId
;
using (var context = new Context())
context.Bills.Add(bill);
context.SaveChanges();
Why it does not get incremented by just 1 ?
I am using EF6 with SQL Server 2017 Express edition.
c# entity-framework-6
This question already has an answer here:
Huge gap in increment value of identity column
2 answers
In the following table, you can see that billid
column is increased by 1000 at 10th row.
The code to generate new bill
is as follows:
private void NewBill()
var bill = new Bill
BillDate = DateTime.Now,
InUse = true,
Paid = false,
TableId = _tableId,
UserId = frmLogIn.LoggedInUserId
;
using (var context = new Context())
context.Bills.Add(bill);
context.SaveChanges();
Why it does not get incremented by just 1 ?
I am using EF6 with SQL Server 2017 Express edition.
This question already has an answer here:
Huge gap in increment value of identity column
2 answers
c# entity-framework-6
c# entity-framework-6
edited Mar 9 at 9:21
marc_s
586k13011281273
586k13011281273
asked Mar 9 at 6:06
Walchand WarikWalchand Warik
11
11
marked as duplicate by CodingYoshi, Lankymart, marc_s
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 9 at 9:21
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by CodingYoshi, Lankymart, marc_s
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 9 at 9:21
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
4
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27
add a comment |
4
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27
4
4
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27
add a comment |
1 Answer
1
active
oldest
votes
It could be due to various reasons as explained here as pointed out by @CodingYoshi. To avoid such mishaps, you could opt to generate the BillId that you can almost be sure to be sequential by fetching the last BillId and incremeting it by 1.
You could write a function like below
public int NextId()
int lastId = 0;
var billsFromStore = _context.Bills;
if (billsFromStore.Any())
var idsFromStore = _context.Bills.Select(x => x.BillId);
lastId = idsFromStore.Max();
return ++lastId;
you may want to use a lock statement to prevent different thread incrementing the value
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It could be due to various reasons as explained here as pointed out by @CodingYoshi. To avoid such mishaps, you could opt to generate the BillId that you can almost be sure to be sequential by fetching the last BillId and incremeting it by 1.
You could write a function like below
public int NextId()
int lastId = 0;
var billsFromStore = _context.Bills;
if (billsFromStore.Any())
var idsFromStore = _context.Bills.Select(x => x.BillId);
lastId = idsFromStore.Max();
return ++lastId;
you may want to use a lock statement to prevent different thread incrementing the value
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
add a comment |
It could be due to various reasons as explained here as pointed out by @CodingYoshi. To avoid such mishaps, you could opt to generate the BillId that you can almost be sure to be sequential by fetching the last BillId and incremeting it by 1.
You could write a function like below
public int NextId()
int lastId = 0;
var billsFromStore = _context.Bills;
if (billsFromStore.Any())
var idsFromStore = _context.Bills.Select(x => x.BillId);
lastId = idsFromStore.Max();
return ++lastId;
you may want to use a lock statement to prevent different thread incrementing the value
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
add a comment |
It could be due to various reasons as explained here as pointed out by @CodingYoshi. To avoid such mishaps, you could opt to generate the BillId that you can almost be sure to be sequential by fetching the last BillId and incremeting it by 1.
You could write a function like below
public int NextId()
int lastId = 0;
var billsFromStore = _context.Bills;
if (billsFromStore.Any())
var idsFromStore = _context.Bills.Select(x => x.BillId);
lastId = idsFromStore.Max();
return ++lastId;
you may want to use a lock statement to prevent different thread incrementing the value
It could be due to various reasons as explained here as pointed out by @CodingYoshi. To avoid such mishaps, you could opt to generate the BillId that you can almost be sure to be sequential by fetching the last BillId and incremeting it by 1.
You could write a function like below
public int NextId()
int lastId = 0;
var billsFromStore = _context.Bills;
if (billsFromStore.Any())
var idsFromStore = _context.Bills.Select(x => x.BillId);
lastId = idsFromStore.Max();
return ++lastId;
you may want to use a lock statement to prevent different thread incrementing the value
edited Mar 9 at 7:20
answered Mar 9 at 7:14
xariezxariez
9211
9211
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
add a comment |
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
And then get all sorts of race conditions as soon as the code runs in production.
– huysentruitw
Mar 9 at 9:41
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
Why would you do this, to gain what? Also imagine this happens and it will: one thread gets next id of 21, and releases the lock but has more work to do before inserting record into table. Now another thread asks for id, it will also get 21. Boom!
– CodingYoshi
Mar 9 at 13:06
add a comment |
4
Why do you care? It has nothing to do with EF. It is the db server that does this and you cannot control it.
– CodingYoshi
Mar 9 at 6:15
Did you have a look at your table definition??
– Gagan Deep
Mar 9 at 7:03
This has nothing to do with EF - it's a feature in SQL Server - read more about here on dba.stackexchange.com
– marc_s
Mar 9 at 9:27