Can anyone point me to an example of or briefly describe how one would go about creating a custom implementation of a WCF RIA Services DomainService using Linq to SQL as the data access layer but without the use of the .dbml file (this is because the Linq to SQL model is generated by a custom tool, is heavily cutomized, and is of a fairly large database with 50+ tables) and without the VS2010 wizard for creating a DomainService (the wizard is dependant on the .dbml file being available)
Here's a really simple shell of what I tried myself so far:
[EnableClientAccess()]
public class SubscriptionService : DomainService
{
[Query(IsDefault = true)]
public IQueryable<Subscription> GetSubscriptionList()
{
SubscriptionDataContext dc = new SubscriptionDataContext();
var subs = dc.Subscription.Where(x => x.Status == STATUS.Active)
.Select(x =>
new Subscription
{
ID = x.ID,
Name = x.Name
}).ToList();
return subs.AsQueryable();
}
public void InsertSubscription(Subscription sub)
{
if (!sub.ID.IsEmpty())
{
SubscriptionDataContext dc = new SubscriptionDataContext();
Subscription tmpSub = dc.GetByID<Subscription>(sub.ID);
if (tmpSub != null)
{
tmpSub.Name = sub.Name;
dc.Save(tmpSub);
}
else
{
tmpSub = new Subscription();
tmpSub.Name = sub.Name;
dc.Save(tmpSub);
}
}
}
public void UpdateSubscription(Subscription sub)
{
if (!sub.ID.IsEmpty())
{
SubscriptionDataContext dc = new SubscriptionDataContext();
Subscription tmpSub = dc.GetByID<Subscription>(sub.ID);
if (tmpSub != null)
{
tmpSub.Name = sub.Name;
dc.Save(tmpSub);
}
}
}
public void DeleteSubscription(Subscription sub)
{
if (!sub.ID.IsEmpty())
{
SubscriptionDataContext dc = new SubscriptionDataContext();
Subscription tmpSub = dc.GetByID<Subscription>(sub.ID);
if (tmpSub != null)
{
dc.Delete(tmpSub);
}
}
}
}
This seems to work so far. Does anyone see any problem with this approach that I might be missing? I don't want to go too far down the wrong road with this if someone has already tried this way and found some major problems with it.
Thanks for everyone's input.