Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:49:49+00:00 2026-05-26T02:49:49+00:00

I’ve been a few weeks working on a web project, amd mostly thinking how

  • 0

I’ve been a few weeks working on a web project, amd mostly thinking how would I implement data layer. I chosed Entity Framework 4.1, code first model.

So, among lot of other entities , think of PLAYER who has N CHARACTER, that can be in 0..1 GUILD

public class Player
{
    public int Id { get; set; }
    public string Login { get; set; }
    public string Password { get; set; }
    public bool IsLogged { get; set; }
    public DateTime LastActivity { get; set; }
    public DateTime LastLogin { get; set; }
    public DateTime LastLogout { get; set; }
    public string DisplayName { get; set; }
    public string DefaultImage { get; set; }

    public virtual Board Board { get; set; }
    public virtual PlayerData PlayerData { get; set; }
    public virtual ICollection<Character> Characters { get; set; }
}
public class Guild
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string DefaultImage { get; set; }

    public virtual ICollection<Character> Characters { get; set; }
}
public class Character
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual Player Player { get; set; }
    public virtual Guild Guild { get; set; }
    public virtual GuildRank GuildRank { get; set; }
    public virtual Game Game { get; set; }
}

As you can see, there a lot more entities and relationships, but this will work.

Well it does not, this code:

Character character = mod.Characters.Where(c => c.Player == player).FirstOrDefault();

Throws an exception:

Unable to create a constant value of type ‘DataObjects.Player’. Only
primitive types (‘such as Int32, String, and Guid’) are supported in
this context.

I don’t understand why.

I also tried with using [Key] and [ForeingKey] attributes, but I can’t find them! :S (though the where in System.Data.Entity.dll, but the don’t).

So after so many errors, I started to think maybe I got the whole thing wrong…

Any ideas on how to fix the error, or to go in other direction?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:49:49+00:00Added an answer on May 26, 2026 at 2:49 am

    This is stupidity in EF. You cannot compare Player directly. You must compare Ids so your query can be rewritten to:

    int playerId = player.Id;
    Character character = mod.Characters.FirstOrDefault(c => c.Player.Id == playerId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I would like to count the length of a string with PHP. The string
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.