Entity Framework 4 Mapping a Stored Procedure

Update the Model from the database by selecting the Stored Procedure and including it in the model.

Right click on the design surface and choose Add Function Import, select the stored procedure from the list and click Get Column Information, then click the Create New Complex Type button so that there’s an entity to map to.


What’s new in MVVM Light V3

What’s new in MVVM Light V3

Sending messages with callback

Certain classes have been added to the GalaSoft.MvvmLight.Messaging namespace, allowing sending a message and getting a callback from the recipient. These classes are:

* NotificationMessageWithCallback: Base class for messages with callback.
* NotificationMessageAction: A class with string notification, and a parameterless callback.
* NotificationMessageAction: A class with string notification, and a callback with a parameter of type T.

To send a message with callback, use the following code:
view source
01.var message = new NotificationMessageAction(
02. “Hello world”,
03. callbackMessage =>
04. {
05. // This is the callback code
06. if (callbackMessage)
07. {
08. // …
09. }
10. });

To register and receive a message with callback, use the following code:
view source
02. this,
03. message =>
04. {
05. // Do something
07. // Execute the callback
08. message.Execute(true);
09. });
Messenger.Default can be overriden

The Messenger.Default property can also be replaced, for example for unit testing purposes, by using the Messenger.OverrideDefault method. All the public methods of the Messenger class have been made virtual, and can be overridden in the test messenger class.
Sending messages to interfaces

In V2, it was possible to deliver messages targeted to instances of a given class. in V3 it is still possible, but in addition you can deliver a message to instances that implement a certain interface. The message will not be delivered to other recipients.

Use the overload Messenger.Default.Send(TMessage message) where TTarget is, in fact, an interface (for example IDisposable). Of course the recipient must register to receive the type of message TMessage.
Sending messages with a token

Messages can now be sent through the Messenger with a token.

* To send a message with token, use the method overload Send(TMessage message, object token).
* To receive a message with token, use the methods Register(object recipient, object token, Action action) or Register(object recipient, object token, bool receiveDerivedMessagesToo, Action action)

The token can be a simple value (int, string, etc…) or an instance of a class. The message is not delivered to recipients who registered with a different token, or with no token at all.


MVC steps to create a new Model, View and Controller

In the MVC project, select the Models folder and create a new class, Customer.

The Customer class has the following properties:

public class Customer
    public string Id { get; set; }
    public string FullName { get; set; }

Build the solution so that the Customer class will be available when we build the View later on.

In the Controllers folder, create a new Controller, CustomerController and leave the checkbox checked which reads “Add action methods for Create, Update, Delete and Details scenarios”.

In this example, I am going to delete everything but the Index and Details methods.

Now let’s create the view. Right click inside the Index method and choose Add View. Leave the view name Index and in the View data class list, choose Customer so that a strongly typed view will be created based on the Customer class we created above. Choose List from the View content list and click the Add button to generate the Index view.

The Index view will be created in a new Customer folder named Index.aspx and will have all the properties of the Customer class displayed on the page. The generated code looks like this:



<% foreach (var item in Model) { %>

            <%: Html.ActionLink("Details", "Details", new { id=item.Id })%> |
            <%: item.Id %>
            <%: item.FullName %>

<% } %>



One property we need to change is the key which is passed to the Details page. Look for the following line in the generated code:

<%: Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ })%>

We need to change PrimaryKey to be the property of our unique value that will be passed to retrieve a Customer. In this case, the value is Customer.Id so change the line to read:

<%: Html.ActionLink("Details", "Details", new { /* id=item.Id */ })%>
where item is the single instance of a Customer in the Model.


The code behind for our controller looks like this:

public List<Customer> CustomerList;

public CustomerController()
    CustomerList = new List<Customer>();
    var c1 = new Customer() { Id = "1", FullName = "Peyton Manning" };
    var c2 = new Customer { Id = "2", FullName = "Drew Brees" };

// GET: /Customer/

public ActionResult Index()

    // In this case, View is a list of Customers
    return View(CustomerList.ToList());



Next we will add code to the Details method to lookup the Customer based on the link clicked on in the List on the Index view. This will pass the Customer.Id into the Details method and it’s code looks like this:

public ActionResult Details(string id)

    var FindCustomer = CustomerList.Find(result => result.Id == id);
    return View(FindCustomer);

Next we need to create the Details view by right clicking inside the Details method and choosing Add View. Leave the view name Details and in the View data class list, choose Customer so that a strongly typed view will be created based on the Customer class. Choose Details from the View content list and click the Add button to generate the Index view.

A file named Details.aspx will be created in the Customers folder. The generated html looks like this:









    <%: Html.ActionLink("Back to List", "Index") %>

Baptism – Romans 6

 1-3So what do we do? Keep on sinning so God can keep on forgiving? I should hope not! If we’ve left the country where sin is sovereign, how can we still live in our old house there? Or didn’t you realize we packed up and left there for good? That is what happened in baptism. When we went under the water, we left the old country of sin behind; when we came up out of the water, we entered into the new country of grace—a new life in a new land!
 3-5That’s what baptism into the life of Jesus means. When we are lowered into the water, it is like the burial of Jesus; when we are raised up out of the water, it is like the resurrection of Jesus. Each of us is raised into a light-filled world by our Father so that we can see where we’re going in our new grace-sovereign country.

 6-11Could it be any clearer? Our old way of life was nailed to the cross with Christ, a decisive end to that sin-miserable life—no longer at sin’s every beck and call! What we believe is this: If we get included in Christ’s sin-conquering death, we also get included in his life-saving resurrection. We know that when Jesus was raised from the dead it was a signal of the end of death-as-the-end. Never again will death have the last word. When Jesus died, he took sin down with him, but alive he brings God down to us. From now on, think of it this way: Sin speaks a dead language that means nothing to you; God speaks your mother tongue, and you hang on every word. You are dead to sin and alive to God. That’s what Jesus did.