Leave a Reply

11 comments

  1. Dude, I took a gander at your Recipe on Codeplex. Can you confirm my observation you take the ViewModel-first approach?

    foobar Reply

  2. Hi,

    The RecipeBrowser uses the view-first approach for almost any of the screens included. For example, if I navigate between subscreens in the recipe hub, you will see that I’m only initializing a new screen. The viewmodel will be attached automatically. That is what I mean with the view-first approach.

    Hope you like it 😉

    willemm Reply

  3. Hi Willem,

    I think you can simplify your code by replacing the Materialize() method calls with calls to the Translate<>() method of the ObjectContext. This method accepts a DbDataReader and already attaches the created objects to the ObjectContext, so you don’t need to call Bind() anymore and you don’t have to manually attach the child objects. If you want more control you can optionally specify a MergeOption when calling the Translate method.

    Alex van Beek Reply

  4. Hi Alex,

    Tried your method, but it doesn’t seem to attach the objects to the DataContext. It only binds the loaded entities when you invoke the Translate method with an entityset name specified. Like this:

    this.Translate(reader,”Recipes”,MergeOption.OverwriteChanges).FirstOrDefault();

    So it’s not really a big time saver sadly 🙁

    willemm Reply

  5. I think it should attach them to the ObjectContext, since by default it used the AppendOnly MergeOption, so if objects aren’t already tracked, they are appended to the context.

    I just tested it and it seems to work here, relations are also automatically fixed up, if you “Translate” related objects at a later time.

    Alex van Beek Reply

  6. Just noticed the link to the required extensions was incorrect. Corrected it, so people don’t get lost using this sample.

    willemm Reply

  7. Does this work for resultsets that are derived from multiple tables? Most of my resultsets join to multiple tables. Obviously I wouldn’t want to be able to Add new records just read them. Would I just manually add the “table” in the EF diagram?

    Brett Mathe Reply

  8. Yep, you can add the extra join table to the diagram and use this tooling to map a resultset to that table.

    willemm Reply

  9. Hi Willemm,

    The link to EFExtensions seems to be broken. I get an error saying If you see this page, it is because an error occurred in the system while trying to process your request. We apologize for the inconvenience. This error has been reported to our team for analysis.
    Error Log Reference #7ad1fd5e-87f4-46c6-8084-770050ea2613”

    Can you please help.

    Thanks,
    Sonia

    Sonia Reply

  10. hey dude,nice post,was very helpful!!!!

    Ganesh Reply

  11. Firstly thanks for this article.

    I downloaded the EFExtensions (a ZIP of the source). I assume I build it and add a reference to the DLL. (I don’t want to all 3rd party projects to my existing solution). I think this could be clearer in your article.

    My next assumption was that there would be a way of supporting multiple result sets without having to write the code myself by hand. It feels like I lose all the benefits of EF (update model from DB and vice versa) so I might as well write the vanilla ADO.NET SqlConnection, SqlCommand code.

    Bernhard Hofmann Reply