Answer the question
In order to leave comments, you need to log in
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; }
}
public class ContactsContext:DbContext
{
public DbSet<Contact> Contacts { get; set; }
public DbSet<Telephone> Telephones { get; set; }
}
public class ServiceContacts : IServiceContacts
{
ContactsContext contactContext;
public IQueryable<Contact> GetAllContact()
{
contactContext = new ContactsContext();
var contacts = contactContext.Contacts.Where(m => m.ContactId > -1);
return contacts;
}
}
public ActionResult Index()
{
var service = new ServiceReference1.ServiceContactsClient();
var contacts=service.GetAllContact();
return View(contacts);
}
Answer the question
In order to leave comments, you need to log in
The answer is found, it turns out that only standard types can be passed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question