Kamis, 24 Januari 2008

LinQ Example

How To Get End result as List
-------------------------------
public IList GetAllEntity()
{
var r = (from s in Manager.Context.CalculationFormula select s.Code).ToList();
return r;
}
How to Get just One Row Result
----------------------------------
public CalculationFormula GetbyCode(string code)
{
var r = (from s in Manager.Context.CalculationFormula
where s.Code==code
select s).Single();
return r;
}
How to Order the Result
-----------------------
return Entity.GetByJobiD(ID).OrderBy(s=>s.RowIndex).ToList();
How to Lazy loading
----------------------
I assume the meaning is, because on each object we have one to many relation ship you can told linq to hold/postpone the loading of these related data by setting it's differedloading=false;
How to get datatable
----------------------
unfortunately you have to have your datatable as source first, there's no way of returning as datatable, so from datatable source you can Query it again againts it. and return as a new datatalbe result using linq.datasetextension.dll the method name is , .CopyasDatatable() or .CopyasDataView()
HOw to join to several tables, join, etc,
-----------------------------------------
Now linq can get very complex, and hierrachiall(does this spell right?)
but it's your job to find out.

Tidak ada komentar: