Monthly Archives: November 2008

How to have all the no deleted entities?

With Northwind, if you do this: context.Categories you will get all the categories which are in DB. It means that you won’t have context added categories and you will have deleted entities. Now, if you do this: context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified … Continue reading

Posted in 7671, 7674 | Leave a comment

How to delete all the related entities?

With Northwind, how to delete all the orders of a customer? You can do this: foreach (var o in customer.Orders.ToArray())     context.DeleteObject(o); but in this case, you will only delete the orders loaded in the context. To delete all the … Continue reading

Posted in 7671, 7674 | Leave a comment

How to split a data table v2?

I wrote a post which explains how to split a data table. But there is a bug in EF and so I couldn’t add a new Category with this EDM. Colin wrote about this bug here. So, in my last EDM, I … Continue reading

Posted in 7671, 7674 | Leave a comment

EF: Attach a graph

In a lot of cases (WCF scenario for example) we need to attach a graph to a context. But the graph can be modified when it is detached. So you have to apply modifications when you attach it back. To … Continue reading

Posted in 7671, 7674 | 7 Comments

How to solve a big EDM performance problem?

Last week, a customer asked me how to solve a big EDM performance problem? In his case, his model was mapped on around 700 tables. I am amused and happy to see that I proposed what Srikanth proposed yesterday: Do … Continue reading

Posted in 7671, 7674, 7675 | Leave a comment

How to simulate a 1 to 0..1 relationship when you must have a 1 to 1

If you take the Noam edm, you have a 1 to 1 relationship that you must have because the relationship is on the PK of the two entities which are the same. Now imagine that in his sample, FrontImage, TopImage … Continue reading

Posted in 7671, 7674 | Leave a comment

How to split a data table?

In this msdn thread, zeeshan hirani wants to split a data table in two entities to do a sort of delay loading? So how to do this? I do this with Northwind: <!– EF Runtime content –> <edmx:Runtime>     <!– … Continue reading

Posted in 7671, 7674, 7675 | Leave a comment

How to dress up to a wedding?

When you are invited to a wedding, you have to be fashionable. But if the groom works in computing, an important grand shirt is a little too conservative and the best is this:

Posted in 8364 | Leave a comment

Get added entities in the query (next)

I want to complete my yesterday post. If you just want to get the entities Count, it is useless to load all the entities in memory. So in this case, it’s better to do something like this: context.MyEntitySet.Count() + context.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(e => e.Entity).OfType<MyEntityType>().Count() … Continue reading

Posted in 7671, 7674 | Leave a comment

C# compiler and implicit keyword: can be better

Imagine the following code: class A {     public static implicit operator B(A a)     {         return new B(a);     } } class B {     public B(A a)     {     } } This code compile without … Continue reading

Posted in 7671, 7672, 7806 | Leave a comment