Archive

Posts Tagged ‘mass delete’

Magiq: New release and API Changes

April 28, 2011 Leave a comment

New release of Magiq, supporting Linq-to-sql. This should be the last one for Linq-to-sql, the next one I hope will have the minimal support for Entity Framework. You can download it from here.

For those reading this for the first time (?), Magiq is a framework that let you do mass operation in a Linq fashion.

So… as Magiq will be supporting Entity Framework soon, it made sense to change the API to make it support Entity Framework limitations. Also, I found a better Insert API (the one that always made me doubt!). The changes are:

Query extension method changes
The new method looks like this:

country.Query(x => x.Cities); 

It will return an IQueryable that will let you do all the Magiq stuff.

No more IEnumerable support
This is a hard one. You can only do Magiq stuff between IQueryables. If you have an IEnumerable collection, use the Query extension method of it parent entity.

New Insert API

destination.Insert( source.Where( condition ).Select( new Item{ ... } ));

Cool, isn’t it? 🙂

Entities extension methods
Because we no longer support extension methods over collections but over the entity, there are some extension methods for improving the code readavility.

Delete

entity.Delete(x => x.Collection.Where( condition ));
//Instead of 
entity.Query(x => x.Collection).Where( condition ).Delete();

Update

entity.Update(x => x.Collection.Where( condition ).Set(x => x.Prop, value));
//Instead of 
entity.Query(x => x.Collection).Where( condition ).Set(x => x.Prop, value).Update();

Query

entity.Query(x => x.Collection.Where( condition ));
//Instead of 
entity.Query(x => x.Collection).Where( condition );

Insert

entity.InsertInto( x => x.Collection, source.Where( condition ).Select( new Item{ ... } ));
//Instead of
entity.Query(x => x.Collection)
      .Insert( source.Where( condition ).Select( new Item{ ... } ));

Magiq-to-NHibernate: Collection filtering and moving to NHibernate 3

February 25, 2010 1 comment

Few days ago I started having troubles with Linq-to-NHibernate from the current release 2.1.2. The main problem cames when I design the collection filtering strategy. Basically, my idea was to go from:

parent.ChildCollection

to:

session.Linq<Child>().Single( x=>x.Id == parent.Id ).SelectMany( x=>x.ChildCollection );

Having this, we could add many expressions to that queryable as we want.

The thing is, as Chadly posted, Linq-to-nhibernate 1.0 uses the query parameter (the x in the previous expression) as the criteria alias, so this works:

session.Linq<Child>()
       .Single( x=>x.Id == parent.Id )
       .SelectMany( x=>x.ChildCollection, (p,x) => x )
       .Where( x => x.Something );

but this doen’t:

session.Linq<Child>()
       .Single( x=>x.Id == parent.Id )
       .SelectMany( x=>x.ChildCollection, (p,x) => x )
       .Where( z => z.Something );

Since the chosen strategy for dynamically generating the query involved the definition of the “alias” parameter, and the user will need to know which is, I gave up. So I tried NHibernate 3. And it worked 🙂

It was really painful to change what I’ve done for the old linq provider, because it uses criteria and the new one uses hql. It’s not easy at all to get a IDbCommand from a HQL, but not impossible.

By now, deletes, updates, inserts and bulkinserts are working properly for linq-to-nhibernate 2.0 with the same limitation as before: no inheritance, no collections.
In the next days I will be working on collection support, composite ids and mappings.

Magiq-to-NHibernate: First commit!

February 22, 2010 1 comment

The past weekend I started to play with NHibernate for getting Magiq-to-NHibernate features up. It’s wonderful to work with an actually well done-designed framework 🙂
By now, only updates and deletes are working, and for simple classes that doesn’t have subclasses. Collection operations aren’t done either. Oh, and also it only works with SQL Server.
I know the actual problem will be when adding support to joined and union subclasses… well… one step at a time 🙂

Magiq 0.3.0 available!

February 17, 2010 Leave a comment

I’m glad to announce that the new version of Magiq is available.
Magiq now support:

  • Plugin model
  • BulkCopy as a Plugin for using SqlBulkCopy when inserting into sql server from any source.

And also there was a huge refactoring in order to have simplicity when implementing new providers.

You can download this version from here.

Magiq-0.2.0 is avaliable!

January 26, 2010 Leave a comment

I’m glad to annunce that the new version of Magiq is out. You can download it here.

Magiq 0.2.0 supports:

  • Mass operations to Linq-to-sql collections (EntitySet)
  • Collection filterig support for Linq-to-sql
  • Support to sorting and grouping
  • Supports when you want to insert into a repository from another one (for example, insert a lot of entities from a string collection). In this case, it uses the same approach as using a foreach, but it works 😉

First release of Magiq: 0.1.0

January 5, 2010 2 comments

I’m glad to annunce that the first version of Magiq is finished. It fully supports Magiq-to-objects and Magiq-to-sql.
The future plan includes Magiq-to-NHibernate and Magiq-to-Entities.
You can download it here. Also, you can read the brief documentation.

Magiq-to-sql: Associations issue

December 25, 2009 Leave a comment

Following the Magiq saga, I started working on composite primary keys support for magiq-to-sql. With this feature we will be releasing the first version of Magiq, so we are very exited about it.

The first thing I have to say is there isn’t much information out there, so I use the “try&error” technique. My first approach was to declare the primary keys as several columns with “IsPrimaryKey=true” and, for the associations, using all the columns separated with commas in the ThisKey and OtherKey properties. Of course, I didn’t made up that, I saw it here. Good enough, it worked fine!

But (and there’s always a “but”)… doing the unit tests for this feature I realized we didn’t tested the insert and update of an association. I mean, this:

items.Set( x => x.AReference, x => x.AnotherReferenceOfTheSameType ).Update();

and

items.Insert( x => new Thing{ Reference = x.Reference } ).Into( things );

The problem here is that the generated query for this kind of expressions uses joins and subselects and, since I’m using a different query for each update set or value to insert, linq-to-sql will generate a different where for each (and a the parameters will use different table aliases).

The solution I see is to generate one single select for each property but, as I said here, it needs to use a dynamically generated class. I’m afraid I have no choice. I’ll post about it in the next days. If it works, we’ll be releasing Magiq 🙂

Oh, right, merry christmas.