tags:

views:

192

answers:

1

I have 2 tables, Clients and ClientInterests. The PK/FK being ClientID of type GUID

This is my Linq, where I want to insert into the ClientIneterests table

    ClientInterestRegistration clientRegisteration = new ClientInterestRegistration
{
    ClientID = (from v in DB.Clients
                where v.Email.Equals(EmailAddress)
                select new {v.ClientID}).Single(), 

    ClientInterest = SelectedInterests,
    ..
};

Error received is: Cannot implicitly convert type System.Linq.IQueryable<AnonymousType#1> to System.Guid

A: 

First, consider removing new {...} from the query and changing it to:

ClientID = (from v in DB.Clients
            where v.Email.Equals(EmailAddress)
            select v.ClientID).Single()

What you are doing is to create a new structure with the ClientID as its property.

However, you shouldn't work directly with the key column at all. Try setting the Client directly to the object:

Client = (from v in DB.Clients
          where v.Email.Equals(EmailAddress)
          select v).Single()
Mehrdad Afshari
Mehrdad: You solution,ClientID = (from v in DB.Clients where v.Email.Equals(EmailAddress) select v.ClientID).Single()Worked.