locked
Can I map a class directly to an entity RRS feed

  • Question

  • I have this working but I am wondering if their is a better way.   For example sake lets say I have a user control that I created that allows me to enter the name and address of a person.  So I would have fields like FirstName, LastName, Address etc. 

    Then lets say I want to use that user control on multiple silverlight pages but I want it to tie to different tables on the back end such as Vendor, Customer etc.   What I am doing now is creating a simple class called Person and am filling it with my current records data one field at a time and am then passing it to the user control and then popping up the user control which is databound to the class that is passed in. 

    Then onces the popup is closed I manually update the current database record with the fields from the person class.  One other thing to note is that the fields are named slightly different in each table (i.e. VendorFirstName on the vendor table and CustomerFirstName on the customer table).

    My question:  Is their a way to create a class that is somehow automatically mapped to the current record so when something updates in my generic person class it updates automatically back to the right fields.  I am using .Net Ria Services with Linq to SQL.

     Any thoughts are appreciated. 

     

     

    Wednesday, August 26, 2009 3:57 PM

Answers

  • Hi,

    As I understand, you have two silimar table in database, when using .net Ria services, it create 2 entity. Now, you create silverlight control which should be able to bind these 2 entity without much extra work.

    I think one idea is to reshape the database, extract same field of two tables to a new table such as "PersonTable".

    Another idea I could think, in server-side DomainService, define new entity which has shared field of original 2 entity, then creating query and update method which is maped to the original 2 entity. Then, on client side, let usercontrol bind to new entity.

    Thanks,

    Monday, August 31, 2009 11:59 PM
  • Another solution would be to add an interface for your editor and implement it on your entities. For example, your interface could have FirstName and in your Entity you implement that interface. That would allow you to use the editor directly against the entities without having to convert data.

    Tuesday, September 1, 2009 10:01 AM

All replies

  • Hi,

    As I understand, you have two silimar table in database, when using .net Ria services, it create 2 entity. Now, you create silverlight control which should be able to bind these 2 entity without much extra work.

    I think one idea is to reshape the database, extract same field of two tables to a new table such as "PersonTable".

    Another idea I could think, in server-side DomainService, define new entity which has shared field of original 2 entity, then creating query and update method which is maped to the original 2 entity. Then, on client side, let usercontrol bind to new entity.

    Thanks,

    Monday, August 31, 2009 11:59 PM
  • Another solution would be to add an interface for your editor and implement it on your entities. For example, your interface could have FirstName and in your Entity you implement that interface. That would allow you to use the editor directly against the entities without having to convert data.

    Tuesday, September 1, 2009 10:01 AM