views:

137

answers:

0

I am using Linq to Sql to access my SQL Server Database. The database contains some tables that have many to many relationships between them which leads to an awkward syntax in the Linq generated classes where I have to create a link object and associate it with both tables (child and parent), rather than just adding the child to a collection on the parent.

To overcome this, I though I'd use the partial classes generated by Linq to add collection properties to the parent class which I can then use to do this linking for me. This is fine, but it means that the entities have both the new Collection based properties on them, as well as the original link table properties on them. My approach to hiding this ugliness was to implement interfaces for all the entities and only expose the Collections out to client code.

The problem I have is this, if I have a TxRx class which has a TxRxDeployment property that returns a Deployment object, then my interface would look like

public interface ITxRx
{
    public IDeployment TxRxDeployment{get;set;}
    public ICollection<INomenclature> Nomenclatures{get;set;}
}

The problem is that the class TxRx has the following definition:

public class TxRx : ITxRx
{
    Deployment TxRxDeployment(get;set;)
    ...link table properties...
    public ICollection<INomenclature> Nomenclatures{get;set;} //Manually added
}

which obviously doesn't match and thus won't compile (Deployment != IDeployment).

So my question is, is there anyway to get Linq to produce the signature IDeployment TxRxDeployment{get;set;} rather than Deployment TxRxDeployment{get;set;}, or is there another way of hiding the Link table property on the class (supressing them in Intellisense?), or should I just give up?