Hello, My app has quite a lot of entities with relationships. I have a scenario in which the entity should join all the contacts records (One to One). another scenario where I need only limited record without all the joins.
For example, a "service call". This entity contains a number of one-to-one relationships: supplier, customer .. I do not always need access to all information (supplier, customer). Sometimes only the specific information.
So I thought the case where I have only the limited record retrieval I will write a separate function without the joins ..
So I found myself almost duplicates all of my retrieval functions. One, with all the joins (GetServiceCalls()). another without joins (GetServiceCallsLimited()).
This way looks me as wrong. Are there more effective ways?
-I know LazyList but it is one-to-many relationships..
Here is some code ex:
This is the basic function
public IQueryable<Product> GetBasicProducts()
{
return from p in _db.Products
select new Product
{
ProductID = p.ProductID,
IsActive = p.IsActive,
Comment = p.Comment,
ShortDescription = p.ShortDescription,
Sponsorship = p.Sponsorship,
Link = p.Link,
Makat = p.Makat,
Price = p.Price,
Cost = p.Cost,
Name = p.ProductName,
Description = p.Description,
StockAmount = p.StockAmount,
CategoryID = p.CategoryID,
ManufacturerID = p.ManufacturerID,
ModifiedDate = p.ModifiedDate,
WeightUnitMeasureCode = p.WeightUnitMeasureCode,
SizeUnitMeasureCode = p.SizeUnitMeasureCode
};
}
That is the full relationships version
public IQueryable<Product> GetProducts()
{
return from p in _db.Products
join category in GetCategoriesNoChilds() on p.CategoryID equals category.CategoryID
join manufacturer in GetManufacturersNoChilds() on p.ManufacturerID equals manufacturer.ManufacturerID
into manufacturers
from manufacturer in manufacturers.DefaultIfEmpty()
join weightUnit in this.GetUnitMeasures() on p.WeightUnitMeasureCode equals weightUnit.UnitMeasureCode
into weightUnit from wUnit in weightUnit.DefaultIfEmpty()
join sizeUnit in this.GetUnitMeasures() on p.SizeUnitMeasureCode equals sizeUnit.UnitMeasureCode
into sizeUnit
from sUnit in sizeUnit.DefaultIfEmpty()
select new Product
{
ProductID = p.ProductID,
IsActive = p.IsActive,
Comment = p.Comment,
ShortDescription = p.ShortDescription,
Sponsorship = p.Sponsorship,
Link = p.Link,
Makat = p.Makat,
Price = p.Price,
Cost = p.Cost,
Name = p.ProductName,
Description = p.Description,
StockAmount = p.StockAmount,
ModifiedDate = p.ModifiedDate,
Category = category,
CategoryID = p.CategoryID,
ManufacturerID = p.ManufacturerID,
Manufacturer = manufacturer,
Weight = p.Weight,
Size = p.Size,
WeightUnitMeasure = wUnit,
SizeUnitMeasure = sUnit,
WeightUnitMeasureCode = p.WeightUnitMeasureCode,
SizeUnitMeasureCode = p.SizeUnitMeasureCode
};
}
The Q is there is some way to simplifed this? (Above i talked about service call and the code is about products. sory about that. but it is same idea)
Thanks