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 7635573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:27:40+00:00 2026-05-31T07:27:40+00:00

For example I have two entities Class A { public Guid Id {get;set;} public

  • 0

For example I have two entities

Class A
{
 public Guid Id {get;set;}
 public Guid BId {get;set;}
 public B InstanceB {get;set;}
}

Class B
{
 public Guid Id {get;set}
}

B is related to A, on my silver light application I am creating a new instance of A, and also a new instance of B. The new instance of B does not exist yet. But I need the instance of B on my service.

Can I do this without Entity or Association with Ria Service?

Edit:

My Class A :

public partial class lSync{

        // Metadata classes are not meant to be instantiated.
        private lSync() {
        }

        public string ConflictMessage { get; set; }

        public DateTime DateInserted { get; set; }

        public Guid vValuesId { get; set; }

        public Guid ID { get; set; }

        public bool IsConflict { get; set; }

        public bool IsReadyToSync { get; set; }

        public Guid SyncSet { get; set; }

        public vValues vValues { get; set; }

    }

My Ria Service:

[Invoke]
public lSync[] SynchvValuesFromClient(lSync[] syncs) {

        bool noConflict = true;
        foreach (lSync sync in syncs) {
            var servervValue = GetvValuesByID(sync.vValuesId).FirstOrDefault();
            var queuevValues = sync.vValues; //sync.vValues here is null, but my sync.vValuesId is not
            if (servervValue== null) {
                InsertvValues(queueValue);
            }
            else {
                if (servervValue.IsServerConflict(queueValue)) {
                    sync.IsConflict = true;
                    sync.ConflictMessage = "Conflict";
                    noConflict = false;
                    break;
                }
                if (!servervValue.AreValuesEqual(queueValue)) {
                    UpdatevValues(queueValue);
                }
            }
        }

        if (noConflict) {
            this.ObjectContext.SaveChanges();
        }
        return syncs;
    }


    public IQueryable<vValues> GetvValuesByID(Guid ID) {
        return ObjectContext.vValues.Where(t => t.ID == ID);
    }


    public void InsertvValues(vValues model) {
        model.ServerDate = DateTime.UtcNow;
        if ((model.EntityState != EntityState.Detached)) {
            this.ObjectContext.ObjectStateManager.ChangeObjectState(model, EntityState.Added);
        }
        else {
            this.ObjectContext.vValues.AddObject(model);
        }
    }


    public void UpdatevValues(vValuesmodel) {
        model.ServerDate = DateTime.UtcNow;
        this.ObjectContext.vValues.AttachAsModified(model,               this.ChangeSet.GetOriginal(model));
    }

🙁

  • 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-31T07:27:42+00:00Added an answer on May 31, 2026 at 7:27 am

    Edit

    The order is wrong of your method 🙂
    Make an instance of the service before creating instances of the Entities.

    It should be:

    public void SyncToServer() { 
      ContextService service = new ContextService();
      var instanceA = new A(); 
      instanceA.InstanceB = new B(); 
      service.SubmitChanges(); //service.SaveChanges() for LinqToEntities
    }
    

    Are you reloading after a submit because only adding the [Include] attribute in the DomainService MetaData won’t work. You need to do this in the DomainService for LinqToSql

    public A GetA()
    {
      DataLoadOptions dlo = new DataLoadOptions();
      dlo.LoadWith<A>(a => a.InstanceB);
      this.DataContext.LoadOptions = dlo;
      return this.DataContext.APlural.FirstOrDefault( ); //don't know the plural of A.
    }
    

    LinqToEntities:

    public A GetA()
    {
      return this.MyEntitiesContext.APlural.Include( "instanceB" ).FirstOrDefault( ); //don't know the plural of A.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two classes in a PHP application, B extending A for example. Class
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities in my domain model: public class Configuration : DomainEntity {
I am trying to make a simple example of Hibernate. I have two entities:
So I have two custom complex types like this (oversimplified for this example): public
public class Car { public string SomeProperty { get; set; } public Manufacturer Manufacturer
I have two entities, Class and Student , linked in a many-to-many relationship. When
i have an entity that contains two other entities with @ManyToOne relationship. @Entity public
Example: I have two shared objects (same should apply to .dlls). The first shared

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.