我有2个表,客户端和ClientInterests。 PK / FK是GUID类型的ClientID
这是我的Linq,我想在其中插入ClientIneterests表
ClientInterestRegistration clientRegisteration = new ClientInterestRegistration
{
ClientID = (from v in DB.Clients
where v.Email.Equals(EmailAddress)
select new {v.ClientID}).Single(),
ClientInterest = SelectedInterests,
..
};
收到的错误是:
无法将System.Linq.IQueryable<AnonymousType#1>
类型隐式转换为System.Guid
答案 0 :(得分:0)
首先,请考虑从查询中删除new {...}
并将其更改为:
ClientID = (from v in DB.Clients
where v.Email.Equals(EmailAddress)
select v.ClientID).Single()
您正在做的是创建一个以ClientID
为属性的新结构。
但是,您根本不应直接使用键列。尝试将Client
直接设置为对象:
Client = (from v in DB.Clients
where v.Email.Equals(EmailAddress)
select v).Single()