Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top