This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I need to remove a object from the database. For this I use the example from here |
|
|
Also My other question will be - how to tell LightSpeed ORM "Don't do referential integrity checks, let DB handle it". So when I do query = new Query(typeof(DAL.Registry)) { Identifier = 15 }; I don't expect related records to be deleted as well, because I may have other plans for them, and DB handling referential integrity. Please advise |
|
|
The reason they give different SQL is that when you use Query.Identifier = 15, LightSpeed knows that you're referring to an entity with a particular ID, and can optimise association lookups to FK equality comparisons. When you use Entity.Attribute("Id") == 15, however, LightSpeed doesn't parse the expression: effectively it treats it the same as, say, Entity.Attribute("Age") > 50, which can't be handled by FK equality comparisons alone. Update not supporting Query.Identifier was a bug. It will be fixed in the 9 July nightly build. Regarding telling LightSpeed not to null out associations, use RemovalBehaviorAttribute(Action = RemovalBehavior.NoAction) on the association. |
|
|
Now Update is working. Thanks. But i have problem with Remove. i set RemovalBehaviorAttribute(Action = RemovalBehavior.NoAction) on ALL association in project. then i run code var query = new Query(typeof(DAL.User)) { Identifier = Item.UserId }; and it dive Exception "The NoAction Removal Behavior is not compatible with this query." without try run SQL action. I am sure there haven't dependence in DB. What's a problem?
P.S.: i use 3.1.1711.14326 build |
|
|
As the exception indicates, the NoAction behavior is not compatible with running a remove by query (as opposed to removing entities which are in memory). This is due to us not being able to determine if a violation would exist so as to throw on that condition. Ive popped an entry on our backlog to look at implementing this in the future to remove the restriction, but for now if you are using NoAction you will need to remove the entities directly rather than by using a query.
Jeremy |
|
|
1 I have a very simple database of two tables
CREATE TABLE `Registry` ( I generated the following data structure http://screencast.com/t/ZGIwNDA1Mz query = new Query(typeof(ConsoleApplication2.User)) { Identifier = 13};
i have SQL
var user = UOW.Users.FirstOrDefault(u => u.UserID == 13);
(UPDATE Registry SET CreatedBy = NULL WHERE Registry.CreatedBy = 13; DELETE FROM users WHERE users.userID = 13)
2 when do you planed implementing remove by query with NoAction attribute.
P.S.: i use build 3.1.1759.14432 |
|
|
some news? |
|
|
Hi Alexander, There is currently no specific timeframe around when we will add in the NoAction support for when removing by query, however when we do get to looking at this I will put through an update on the forum. In regards to your other issue, are you able to send through a copy of your model and we can have a look at what is happening here.
Jeremy |
|
|
Thanks, I found the solution. There had to set in Entity's properties: "Cascade Deletes" = False |
|