C# generics with linq search criteria -


I am trying to create small supportive methods for simple normal tasks but on the sample:

  public static int getEntityId & lt; Type, unit & gt; (String name) where the body:. Class {type type = _db.gettable & lt; Unit & gt; () SingleOrDefault (t = & gt; t.name == name); Return 0; }  

I get an error:

  Error 1 There is no definition of 'name' in 'entity' and no extension method 'name' first accepted The argument of type 'unit' can not be found (do not you remember the usage instructions or an assembly reference?) C: \ work \ asutp_migration \ asutp_migration \ Program.cs 89 62 asutp_migration  

Actually, this is expected of error, but how to solve it?

UPD 1: According to the advice I did this:

  Public partial square unit: IHasName {} Interface IHasName {string name {get; } Int id {get; }} Public Fixed Integer Entitide & lt; Type, unit & gt; (String name) where unit: class IHasName {type type = _db.getetable & lt; Unit & gt; (). Singleer Default (t = & gt; t.name == Name); Return (type == zero)? Type.id: 0; }  

and with the code:

  int i = getEntityId & lt; Unit & gt; ("М"); Console.WriteLine (i);  

I get an exception:

  Unchecked exception: System.NotSupportedException: The mapping of the interface member IHasName.name is not supported.  

UPD 2: I can not believe it is related to my problem?

UPD 3: Yes, this VS The problem is:

UPD 4:

  public fixed int getEntityId & lt; Type & gt; (String name) where type: square, ihasName {type type = _db.getetable & lt; Type & gt; (). Singular Lower (T = & gt; T. Name Eckels (name)); Return (type! = Null)? Type.id: 0; }  

So this is a solution, thank you all: -)

OK, you will need to create a general barrier that specifies more than class for example, if you have said that where unit: IHasName And IHasName have defined a property name , then you will have all the sets.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -