views:

120

answers:

1

Our ticketing system let's us read the database directly, but updates need to be done either through a web service or an insert to a special "staging" table and then calling a web service to trigger the processing of their business logic.

We have a few classes that manage this currently, but I am rewriting everything to use Entity Framework and wondering if there is a way to make use of that code for Inserts/Updates on the tables that require it.

If it is possible how would I got about doing it?

A: 

That's possible. You should be able to send the entities and related graphs to the service and use these values with minimal changes or create a mapping between the entities and your previous classes. I honestly think it's quite a lot of work but hey if it's not broken why break it now? :)

EDIT:

I'll make a first try. Let's say we have an Ticket, TicketEntity (Entity Framework entity) and an TicketService. The TicketService has a method to update a booking or whatever. I am not familiar with ticket services so I am basically just guessing now. Feel free to correct me if I am wrong :)

public class TicketService
{
    public TicketService()
    {
     public void InsertTicket(Ticket ticket)
     {
      // Logic remains the same
     }
    }
}

public class Ticket
{
    private TicketEntity _entity;
    public Ticket(TicketEntity entity)
    {
     _entity = entity;
    }

    public decimal Price 
    {
     get { return _entity.Price }
    }

    public double GST 
    {
     get { return _entity.GST }
    }
}

public partial class TicketEntity
{
     public decimal Price { get; set; }
     public double GST { get; set; }
}

This is one approach. I am not saying it is right I am just saying this is one way of solving the issue of reusing the current services for updating and inserting tickets.

To use the ticket service from the business layer one would do something like.

public void Get(TicketEntity entity)
{
    var context = new ObjectContext();
    IList<TicketEntity> entities = (from t in context.TicketEntities
            where t.Price > 200
            select t).ToList();
    foreach (var ent in entities)
    {
     var ticket = new Ticket(ent);
     new TicketService().InsertTicket(ticket);
    }
}
mhenrixon
How do I go about it? I can only find documentation on how to use stored procedures...
Telos
This is where I would use some sort of adapter pattern. I'll update my post.
mhenrixon
I've actually abandoned Entity Framework for the project, there are just too many walls in place. Went back to Linq2Sql and have already gotten much further. Too bad, EF looks good... just not there yet.You get the answer credit though, due to lack of any other responses and yours looking correct.Side note: In L2S you can just create a partial function in the data context such as InsertTicket and lets you do any logic you need there...
Telos