I am trying to incorporate Telerik Data Access (using SQLite) into some new development.
One of the requirements is to try to insert data into a table, but only if it does not already exist (using a Unique "Code" value to check the existence, rather than the PK id).
The plan was to use the DataContext as a transaction, so that multiple records can be committed at once, and easily roll backed if an error occurs.
For this to work, the entities to be inserted need to be queried along with the entities already in the database.
I was under the assumption that this is a standard feature of an ORM, and was expecting this to work straight out of the box. Am I missing a setting or something?
Here's some code that may help explain what I'm talking about:
var testTable =
Id = 1,
(var dataContext =
var toBeInserted = dataContext.GetChanges().GetInserts<TestTable>().SingleOrDefault(x => x.UniqueValue ==
Assert.IsNotNull(toBeInserted); //THIS WORKS, BUT WOULD MEAN ALL MY "GETS" WOULD NEED TO SEARCH THIS AS WELL AS GETALL
var contextOnlyRecord = dataContext.GetAll<TestTable>().SingleOrDefault(x => x.UniqueValue ==
var dbRecord = dataContext.GetAll<TestTable>().SingleOrDefault(x => x.UniqueValue ==
//THIS WOULD WORK, BUT ONLY BECAUSE THE RECORD IS NOW IN THE DB