Why am I unable to use TEntity?

entity-framework

Question

Sometimes it feels like even the simplest things are hard to understand. The type TEntity is often used in code references and is utilized for general entity handling in entity data models. Why does it say "Unknown type 'TEntity'" when I try to use it in my code? What does "Unknown kind" mean? Does this just work with.net 4.0?

Using.net 3.5, btw.

I'm attempting to utilize the following code:

public TEntity ExecuteFirstorDefault<TEntity>(ObjectQuery<TEntity> objectQuery)
  {
    try
    {
      return objectQuery.FirstOrDefault();
    }
    catch (EntitySqlException ex)
    {
      throw ex; //TODO: Replace with handling code
      //additional exceptions as described in Chapter 18
    }
  }
1
3
5/27/2011 1:40:09 PM

Accepted Answer

TEntity is not a definite type but a parameter of a general kind.


I guess my question is why I can't use it, why do I get Unknown type.

Since the time is Zzz-18-Zzz

Let's say you have an implementation of a generic list that isList<T> . T is a parameter type, indicating that it is not a particular kind. Instead of using the generic type, the programmer must ask the compiler to use a particular type.T offering a argument type You might make an integer list by doing the following:

List<int> myInts = new List<int>();

The type argument in this example isint . Each of the generic functions (or attributes) ofList that take a and return itT will rather utilizeint .

Additional reading

8
5/27/2011 1:30:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow