W
W
wkololo_4ever2014-03-24 22:47:32
ASP.NET
wkololo_4ever, 2014-03-24 22:47:32

WCF + EF + ASP.NET MVC. How to transfer related data?

More recently, I began to understand WCF.
There are two models

[DataContract]
    public class Telephone
    {
        [DataMember]
        public int TelephoneId { get; set; }
        [DataMember]
        public int Number { get; set; }
        [DataMember]
        public int ContactId { get; set; }
        [DataMember]
        public Contact Contact { get; set; }
    }

[DataContract]
    public class Contact
    {
        [DataMember]
        public int ContactId { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Address { get; set; }
        [DataMember]
        public ICollection<Telephone> Telephone { get; set; }
    }

I use them for EF and WCF.
public class ContactsContext:DbContext
    {
        public DbSet<Contact> Contacts { get; set; }
        public DbSet<Telephone> Telephones { get; set; }
    }

Service Implementation
public class ServiceContacts : IServiceContacts
    {
        ContactsContext contactContext;
        public IQueryable<Contact> GetAllContact()
        {
            contactContext = new ContactsContext();

            var contacts = contactContext.Contacts.Where(m => m.ContactId > -1);
            
            return contacts;
        }
   }

I am trying to call this method in the controller
public ActionResult Index()
        {
            var service = new ServiceReference1.ServiceContactsClient();
            var contacts=service.GetAllContact();
            return View(contacts);
        }

And in some way unknown to me, GetAllContact() returns ServiceReference1.Contact[] and not IQueryable. What is the reason for this and how can I display data from the dependent table (Telephones)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wkololo_4ever, 2014-03-25
@wkololo_4ever

The answer is found, it turns out that only standard types can be passed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question