Reputation: 845
I am using Entity Framwork Code First and i have a table Session (Id primary key long not null, SessionId UniqueIdentify not null) and my entity Session:
public class Session
{
public long Id { get; set; }
public string SessionId { get; set; }
public string Status { get; set; }
}
when i Create the session it is ok get no exception but when i get Session By Status I getting an Error "The 'SessionId' property on 'Session' could not be set to a 'System.Guid' value. You must set this property to a non-null value of type 'System.String'"
My GetSessionByStatus Method :
public QueryResult<Session> GetSessionByStatus(DbConnection connection, string status, int size = 0, int index = 0)
{
QueryResult<Session> result = new QueryResult<Session>();
try
{
using (var uow = new StagingUnitOfWork(connection))
{
result.Data = uow.SessionRepository
.FindAll(s => (s.Status == status)).Skip(size * index).Take(size).ToList();
if (result.Data != null && result.Data.Count() > 0)
{
result.QuerySuccess = true;
result.Message = "Query Session Data Successful";
}
else
{
result.QuerySuccess = false;
result.Message = "Session have no result";
}
}
}
catch (Exception ex)
{
result.Data = null;
result.QuerySuccess = false;
result.Message = ex.Message;
}
return result;
}
The Resule.Data throw that exception. Please help me fix this Exception Thank for advance
Upvotes: 0
Views: 1313
Reputation: 137
You are asking for your database value, stored as a Guid, to be placed into a String. You can probably set SessionID in your object as Guid instead of string to fix this.
Upvotes: 2