Insert doesn't send pk column
See original GitHub issueHi,
After migrating from EF to Linq2db.EntityFramework everything worked as expected, but I wanted to migrate DML also to Linq2Db, so that I could eventually remove EF completely.
From some reason, insert doesn’t work. I have some simple table :
[Table("...", Schema = "...")]
public class NaseljenoMjestoEntity
{
[Key]
public int? NaseljenoMjestoId { get; set; }
[Required]
public string Naziv { get; set; }
...
}
I’ve used this code to try to insert:
using (var context = _dbContext.CreateLinqToDbConnection())
{
var result= context.Insert(entity);
}
but it doesn’t work. Query generated for insert contains all columns except NaseljenoMjestoId, so naturally, it throws Cannot insert the value NULL into column ‘NaseljenoMjestoId’…
NaseljenoMjestoId is Nullable<int>, but changing it to int doesn’t change anything.
We have more than 1000 entities, so I was hoping to reuse EF annotations so that I wouldn’t have to regenerate all the entities (most of them have some kind of custom modifications). It’s ease to replace Key to PrimaryKey, but ForeignKey attribute doesn’t have ‘OtherKey’ part, so it would be tedious to try to manually replace all ForeignKeys to Association.
What am I doing wrong? Is this use case event possible (to create DataConnection from DbContext and do insert, based on EF annotations)?
I’m using linq2db.entityframeworkcore 3.0.0
Also, what is the difference between DataConnection and DataContext? What are different use cases for both of them?
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (8 by maintainers)
Top GitHub Comments
I would always trade that for your functionality and simplicity. Keep up with good work.
Closing for now, will reopen if needed.