Couldn't insert a record with nullable id
See original GitHub issueTL;DR: Repository with the tests. More specifically:
Model:
public class Customer
{
public int? Id { get; set; }
public string Name { get; set; }
}
Test:
var col = _liteDatabase.GetCollection<Customer>();
var customer = new Customer
{
Name = "John Doe",
};
col.Insert(customer);
Assert.True(col.Exists(x => x.Id == customer.Id));
Actually col.Insert
throws an exception:
LiteDB.LiteException : Invalid BSON data type ‘Null’ on field ‘_id’.
Fails for both LiteDatabase
and LiteRepository
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Cannot insert the value NULL into column 'id'?
When you created table you have not indicate ' ID ' column to be Auto Increment hence you get this error. By making...
Read more >Can't insert a record with NULL value in nullable ...
When a record has a NULL value, or when I assign the NULL value by selecting the empty string, all works fine and...
Read more >Cannot insert the value NULL into column and ...
[ProdID] [int] IDENTITY(1,1) NOT NULL. I am trying to insert the records into this prod table using the destination table values ,insert ......
Read more >I'm Getting a Cannot Insert the Value NULL Into Column 'ID' ...
INSERT fails.” Something like this: Error: Cannot insert the value null into column ID. You look at your SQL statement first, to see...
Read more >Msg 515 - Cannot insert the value NULL into column ' ...
As the message suggests, you are trying to insert a new record into a table and one of the columns is being assigned...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
BTW: null and 0 are not the same. Null means it has not been set. 0 means it has been set… to 0.
I would think there’s a strong argument for Auto Increment Id properties to be int? so we know they have not been set.
Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!