Bulk insert with SQLAlchemy ORM

SQLAlchemy introduced that in version 1.0.0: Bulk operations – SQLAlchemy docs With these operations, you can now do bulk inserts or updates! For instance, you can do: s = Session() objects = [ User(name=”u1″), User(name=”u2″), User(name=”u3″) ] s.bulk_save_objects(objects) s.commit() Here, a bulk insert will be made.

Entity Framework .Remove() vs. .DeleteObject()

It’s not generally correct that you can “remove an item from a database” with both methods. To be precise it is like so: ObjectContext.DeleteObject(entity) marks the entity as Deleted in the context. (It’s EntityState is Deleted after that.) If you call SaveChanges afterwards EF sends a SQL DELETE statement to the database. If no referential … Read more

Hibernate Annotations – Which is better, field or property access?

There are arguments for both, but most of them stem from certain user requirements “what if you need to add logic for”, or “xxxx breaks encapsulation”. However, nobody has really commented on the theory, and given a properly reasoned argument. What is Hibernate/JPA actually doing when it persists an object – well, it is persisting … Read more

How do I map lists of nested objects with Dapper

Alternatively, you can use one query with a lookup: var lookup = new Dictionary<int, Course>(); conn.Query<Course, Location, Course>(@” SELECT c.*, l.* FROM Course c INNER JOIN Location l ON c.LocationId = l.Id “, (c, l) => { Course course; if (!lookup.TryGetValue(c.Id, out course)) lookup.Add(c.Id, course = c); if (course.Locations == null) course.Locations = new List<Location>(); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)