Question: I have two models:

User

```
has_one :email

```

Email

```
belongs_to :user

```

I put the email\_id foreign key (NOT NULL) inside users table.
Now I'm trying to save it in the following way:

```
@email = Email.new(params[:email])
@email.user = User.new(params[:user])
@email.save

```

This raises a db exception, because the foreign key constraint is not met (NULL is inserted into email\_id). How can I elegantly solve this or is my data modeling wrong?

Answer: 
Yes, but only by invoking it:

```
Func<object> func = delegate { return a; };
// or Func<object> func = () => a;
object b = func();

```

And of course, the following is a lot simpler...

```
object b = a;

```

---

In the comments, cross-thread exceptions are mentioned; this can be fixed as follows:

If the delegate is the thing we want to run back on the UI thread *from* a BG thread:

```
object o = null;
MethodInvoker mi = delegate {
    o = someControl.Value; // runs on UI
};
someControl.Invoke(mi);
// now read o

```

Or the other way around (to run the delegate on a BG):

```
object value = someControl.Value;
ThreadPool.QueueUserWorkItem(delegate {
    // can talk safely to "value", but not to someControl
});

```
Just declare somewhere these static functions:

```
public delegate object AnonymousDelegate();

public static object GetDelegateResult(AnonymousDelegate function)
{
    return function.Invoke();
}

```

And anywhere use it as you want like this:

```
object item = GetDelegateResult(delegate { return "TEST"; });

```

or even like this

```
object item = ((AnonymousDelegate)delegate { return "TEST"; }).Invoke();

```