Reputation: 13521
Lets say I've got an object model, where I have many collections of the same type.
For example something like
class StockMarketData {
List<SummaryData> WeeklySummary;
List<SummaryData> MonthlySummary;
}
class SummaryData {
DateTime DateTime {get; set;}
double Value {get; set;}
}
Those lists will map onto database tables.
If you actually use L2S to generate a model from the database you will get something like:
class StockMarketData {
List<WeeklySummaryData> WeeklySummary;
List<MonthlySummaryData> MonthlySummary;
}
Even though WeeklySummaryData and MonthlySummaryData have the same shape.
Is it possible for Linq to SQL to create tables from a database of summary data, but get each table to contain the same type (such as shown in the top example).
Upvotes: 1
Views: 66
Reputation: 956
This scenario is supported in the designer in the entity framework, but not in the designer (dbml) in linq to sql.
To go down the more manual path, create a class that is not a database entity, called SummaryData
and populate the class when you Select either the WeeklySummaryData
or MonthlySummaryData
. You can then expose properties like this off the DataContext partial class (View Code on the dbml):
IQueryable<SummaryData> WeeklySummary
{
get
{
from wsd in WeeklySummaryData
select new SummaryData { DateTime = wsd.DateTime, Value = wsd.Value }
}
}
IQueryable<SummaryData> MonthlySummary
{
get
{
from msd in MonthlySummaryData
select new SummaryData { DateTime = msd .DateTime, Value = msd.Value }
}
}
Upvotes: 2