views:

25

answers:

1

hi,

So similar questions have been asked with not much of an answer....

I have a Stats Table related to a Branch table. The Stats records contain pc stats of a particular bank branch.

Branch
+Code
+Name
+Area
...

Stats
+BranchCode
+IP
+UpSpeed
+DownSpeed
...

Here is my linq query...

var stats = from st in store.Stats
                        join b in store.Branches on st.BranchCode equals b.Brcd
                        select new
                        {
                            st.ID,st.IP,st.Name,b.Brcd,b.Branch_Name..............
                        };

The issue is st and b have a LOT of fields, for now I guess I will type them all... but isn't there a solution to this? *Prevent the typing of all fields... something like a * wildcard?

Did try intersect however the types need to be the same!

Thanks Gideon

A: 

1

var stats =
  from st in store.Stats 
  join b in store.Branches on st.BranchCode equals b.Brcd 
  select new 
  { 
    Stats = st,
    Branch = b
  };

Creates anonymous instances with one Stats and one Branch.


2

var stats =
  from b in store.Branches
  join st in store.Stats 
    on b.Brcd equals st.BranchCode
    into branchstats
  select new 
  { 
    Branch = b
    Stats = branchstats
  };

Creates anonymous instances with one Branch and its Stats.


3

var stats =
  from b in store.Branches
  select new 
  { 
    Branch = b
    Stats = b.Stats
  };

Same as 2, If there's an association between the two types in the designer, then there's a relational property generated on each type.


4

DataLoadOptions dlo = new DataLoadOptions()
dlo.LoadWith<Branch>(b => b.Stats);
store.LoadOptions = dlo;

List<Branch> branches = store.Branches.ToList();

Here, DataLoadOptions are specified that automatically populate the Stats property when any Branch is loaded.

David B
hi,The problem is I need it all FLAT.... all solutions have a hierarchical resultset. I would have to access it like this stats.Branches and stats.Stats. The reason is, after the result is generated it goes into another function which turns it into CSV for exporting. And that function parses only a flat table resultset. Thanks
giddy
guess there is no real * operator equivalent in Linq? Since I needed a flat tabular result I just typed in all the columns anyway!! =P
giddy