我收到此錯誤:無法從轉換‘詮釋’到‘System.Predicate ServerHomeWork.Models.Organisation’無法從「詮釋」轉換爲「System.Predicate
在行OrgList的一部分。加入(Organisation.Find(UTO.OrganisationId); 財產UTO.OrganisationId是int但仍說,什麼是錯誰能告訴我是怎麼回事錯在這裏
的代碼是在這裏:
?public virtual List<Organisation> Organisation
{
get
{
List<UsersToOrganisations> UserToOrg = UsersToOrganisations.FindListOfOrganisations(UserId);
List<Organisation> OrgList = new List<Models.Organisation>();
if (UserToOrg.Count > 0)
foreach (UsersToOrganisations UTO in UserToOrg)
OrgList.Add(Organisation.Find(UTO.OrganisationId));
else
OrgList.Add(new Organisation("No organisation was found.", 0));
return OrgList;
}
}
這是UserToOrganisation類
class UsersToOrganisations
{
public int Id { get; set; }
public int UserId { get; set; }
public int OrganisationId { get; set; }
public bool MainOrganisation { get; set; }
/// <summary>
/// Constructor for entity framework
/// </summary>
public UsersToOrganisations() { }
/// <summary>
/// Constructor for creation
/// </summary>
/// <param name="UserId"></param>
/// <param name="OrganisationId"></param>
public UsersToOrganisations(int UserId, int OrganisationId, bool MainOrganisation)
{
this.UserId = UserId;
this.OrganisationId = OrganisationId;
this.MainOrganisation = MainOrganisation;
}
public class UsersToOrganisationsContext : DbContext
{
public DbSet<UsersToOrganisations> UserToOrganisation { get; set; }
}
/// <summary>
/// Get the list of organisations of a single user
/// </summary>
/// <param name="UserId"></param>
/// <returns></returns>
public static List<UsersToOrganisations> FindListOfOrganisations(int UserId)
{
using (var context = new UsersToOrganisationsContext())
{
var organisation = (from uto in context.UserToOrganisation
where uto.UserId == UserId
select uto);
return organisation.ToList();
}
}
/// <summary>
/// Get the main organisation of a user
/// </summary>
/// <param name="UserId"></param>
/// <returns></returns>
public static UsersToOrganisations FindMainOrganisation(int UserId)
{
using (var context = new UsersToOrganisationsContext())
{
var UserToOrganisation = context.UserToOrganisation
.Where(uto => uto.UserId == UserId && uto.MainOrganisation == true)
.SingleOrDefault();
return UserToOrganisation;
}
}
}
AREN '你錯過了關閉'''在那裏? – Idos
對不起,我做到了。但Visual Studio給出的消息仍然是一樣的。 – StuiterSlurf