Question: ASP.NET MVC how can I check if instance of a class already exists before creating a new one? Here is the class:

```
public class Doctor
{
    public int Id {get;set;}
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public string Address {get;set;}
}

```

In the controller:

```
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "Title,Id,FirstName,LastName,Address,Facility,IsAvailable")] Doctor doctor)
    {
        if (ModelState.IsValid)
        {
            db.Doctors.Add(doctor);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(doctor);
    }

```

How can I check if the dcotor already exists, by comparing firstName and LastName? I think I need something like: 

`var doctors = from d in db.Doctors select d;`

```
doctors = doctors.FirstOrDefault(d => d.FirstName == search && d.LAstName == searchlast); return RedirectToAction("Index", "Doctor");

```

Basically if the doctor already exists I do not want to be able to create a new one.

Answer: 
Should be possible like this 

```
 interface TriggerInterface<T: TriggerInterface<T>> {
    val trigger: (T) -> Unit
    fun triggerNow()

    fun getThis(): T
 }

 interface Triggerable<T: TriggerInterface<T>>: TriggerInterface<T> {
     override fun triggerNow() = trigger(getThis())
 }

 class Test : Triggerable<Test>{
     override fun getThis(): Test = this

     override val trigger: (Test) -> Unit = { /*...*/ }
 }

```

Check <http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206>

I would also personally recommend to reconsider if you really need both TriggerInterface AND Triggerable (where one inherits from the other).
Calling `override fun triggerNow() = trigger(this as T)` you are trying to cast `Triggerable<T>` to `T` thats why compiler warns you about unchecked cast

having

```
    val trigger: (TriggerInterface<T>) -> Unit

```

will allow you to call trigger with no casting

```
    override fun triggerNow() = trigger(this)

```

to actually execute 

```
override val trigger: (Test) -> Unit = { /*...*/ }

```

you need an instance of `Test` to pass inside of trigger which is not declared anywhere in your code yet