I have an entityDao that is inherited by all my Daos objects. I am using Dynamic Linq and trying to get some common queries to work.
I have the following code in my generic method in my EntityDao:
public abstract class EntityDao<ImplementationType> where ImplementationType : Entity
{
public ImplementationType getOneByValueOfProperty(string getProperty, object getValue){
ImplementationType entity = null;
if (getProperty != null && getValue != null)
{
LCFDataContext lcfdatacontext = new LCFDataContext();
entity = lcfdatacontext.GetTable<ImplementationType>().Where(getProperty + " =@0", getValue).FirstOrDefault();
}
return entity;
}
Then I call the following method call in unit test (my entire ObjectDaos object inherits entityDao):
[Test]
public void getOneByValueOfProperty()
{
Accomplishment result = accomplishmentDao.getOneByValueOfProperty
("AccomplishmentType.Name", "Publication");
Assert.IsNotNull(result);
}
The above omissions (AccomplishmentType is related to achievement)
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("Description", "Can you hear me now?");
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("LocalId", 4);
Both of these work. Nonetheless,
Accomplishment result = accomplishmentDao.getOneByValueOfProperty
("Id", New Guid("95457751-97d9-44b5-8f80-59fc2d170a4c"));
It does not work and says the following:
Operator '=' incompatible with operand types 'Guid' and 'Guid
Why is this happening? Can't the guide compare? I also tried ==, but the same error. What is even more confusing is that in each Dynamic Linq example I just saw lines using the parameter where the predicate or this one I commented out:
//.Where(getProperty & "==" & CStr(getValue))
Cstr . getValue , (, ).
, GUID / ? getValue ( LINQ) .