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

  • SEARCH
  • Home
  • 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 6895893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:58:00+00:00 2026-05-27T06:58:00+00:00

i use Entity Framework one to one relationship in WCF server-side,Main code is: [DataContract]

  • 0

i use Entity Framework one to one relationship in WCF server-side,Main code is:

[DataContract]
public class AppType
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [DataMember]
    public int TypeID { get; set; }

    [DataMember]
    public string TypeName { get; set; }
}

[DataContract]
public class App
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [DataMember]
    public long AID { get; set; }

    [DataMember]
    [ForeignKey("AppType")]
    public int TypeID { get; set; }

    [DataMember]
    public DateTime DateAdded { get; set; }

    [DataMember]
    public virtual AppType AppType { get; set; }
    //...
}

Because the Serialize Problem,i must close lazyloading and proxyclass in EF:

this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;

Now,the WCF Client-side can work,but i can’t get “AppType” by “App”:
enter image description here

the GetAppByTypeidContentid method is:

public App GetAppByTypeidContentid(string contentid, int typeid)
{
    using (var db = new TagDbContext())
    {
        try
        {
            var app = db.Apps.SingleOrDefault(a => a.ContentID.Trim() == contentid.Trim() && a.TypeID == typeid);
            if (app != null)
            {
                return app;
            }
            else
            {
                throw new Exception("App not exist!");
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
}

Is must use DTO or not? who can help me?thanks

  • 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-27T06:58:01+00:00Added an answer on May 27, 2026 at 6:58 am

    You turned off lazy loading so you must tell EF to load AppType:

    var app = db.Apps.Include("AppType")
                .SingleOrDefault(a => a.ContentID.Trim() == contentid.Trim() && a.TypeID == typeid); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the entity framework to take data (nested relationships) from one
I'm using Entity Framework 4.1 and trying to create a one-to-many relationship. In my
I use Entity Framework 4 and I have parent - child relation with Cascade
I've decided to use Entity Framework for O/R Mapping, and DataAnnotations for validation in
i search a good tutorial to learn how to use entity framework in the
For my ASP.NET MVC 2 application I use Entity Framework 1.0 as my data
Is it possible to use Microsoft Entity Framework with Oracle database?
I'm planning to use MS entity framework for new web apps (come on EF
I am developing a rich client application that will use the Entity Framework (with
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity

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.