Results 1 to 2 of 2

Thread: Explicit construction of entity type 'rentalAlertUtilities.RentalAlertCityState' in q

  1. #1

    Thread Starter
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Explicit construction of entity type 'rentalAlertUtilities.RentalAlertCityState' in q

    Hi there,

    OK - I am missing something here... Obviously there is a better way to do this cause while it doesn't throw an exception this is what I get
    Code:
    base {System.SystemException} = {"Explicit construction of entity type 'rentalAlertUtilities.RentalAlertCityState' in query is not allowed."}
    I know that my list of contacts has a rentalAlertCityState object and I want to grab any properties that match that city and state. Hmm... maybe just looking at my code will show you what I am trying to do.

    I am really stretching my limits of understanding here, but I guess that is how you learn right!

    Code:
    var matchingProperties = from p in properties
                         where int.Parse(p.Bedrooms) >= contact.MinBedrooms
                         && int.Parse(p.Bathrooms) >= contact.MinBathrooms
                         && p.RentRate >= contact.RentRangeMax
                         && p.RentRate <= contact.RentRangeMin
                         && p.DogsAllowed == contact.DogsAllowed
                         && p.CatsAllowed == contact.CatsAllowed
                         && contact.RentalAlertCityStates.Contains(new RentalAlertCityState { City = p.City, State = p.State })
                         select p;
    Thanks for any advice!
    Anti DUPLO machine!!!

  2. #2

    Thread Starter
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Re: Explicit construction of entity type 'rentalAlertUtilities.RentalAlertCityState'

    before this conversation gets derailed I would like to point out there are a couple of errors in the original code that don't have anything to do with what I was asking about, I didn't see them cause I was concentrating on the problem with the explicit construction of an entity.

    Also - What I meant by "it doesn't cause an exception" was that noting fails - if you weren't debugging you might simply think you did not get back any results...

    At any rate - for the moment disregarding the mismatch of the bedrooms and bathrooms (can't tell you for the life of me why they are varchars...) here is a working solution however it seems to me like the "Brute force and ignorance" solution

    Code:
    var cities = from ra in contact.RentalAlertCityStates select ra.City;
    var states = from rs in contact.RentalAlertCityStates select rs.State;
    var matchingProperties = from p in properties
                               //where p.Bedrooms  >= contact.MinBedrooms
                               //&& p.Bathrooms >= contact.MinBathrooms
                               where p.RentRate <= contact.RentRangeMax
                               && p.RentRate >= contact.RentRangeMin
                               && p.DogsAllowed == contact.DogsAllowed
                               && p.CatsAllowed == contact.CatsAllowed
                               && cities.Contains(p.City)
                               && states.Contains(p.State)
                               //&& contact.RentalAlertCityStates.Contains(new RentalAlertCityState { City = p.City, State = p.State })
                                             select p;
    It seems as thought I should somehow be able to this with an anonymous function (lambda or anonymous method) but I am stumped.

    Sorry for the confusion in my first post!

    Thanks!
    Anti DUPLO machine!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width