.net - Convert Type1 To Type2 Using LINQ With Subselect Projection?

Mar 3, 2011

In the following code I want the project Id and name of TList and cast them to List. How do I do that?

List<ListItem> nameItems = new List<ListItem>();
TList<ProductCode> items = GetAllProductCode();
//WANT TO SUBSELECT ID, NAME OF ITEMS IN nameItems
nameItems = (from item in items select new (item.Id, item.Name)).Cast<ListItem>();

View 1 Replies


Similar Messages:

DataSource Controls :: Linq To Entities - Multilevel Projection Into Business Class And Not Breaking Deferred Execution?

Mar 18, 2010

I have a problem. (this a simplfied example)

In Entity framework I have a class which is effectively

fooEntity
{
public Guid Id {get; set;}
and a collection of fooChildEntity
}
a fooChildEntity is again an entityframework class
fooChildEntity
{
public Guid kidId {get; set;}
}

Now I also have a pair of business layer classes foo and fooChild

foo
{
public Guid Id {get; set;}
ilist<fooChild> Children {get;set;}
}
fooChild
{
public Guid kidId {get; set;}
}

My aim is to write a linq to entites that will allow me to convert the entity foo and children into the business foo and children without breaking deferred execution ( I will be adding filters to reduce the recordset at a higher coding level in the business layer)

doing something like

this.context.fooEntity

.include(fooChildEntity)

.Select( fe => new foo { Id=fe.Id ,

fe.foreach(fec => Children.add( new fooChild { kidId = fec.kidId}))})

.AsIQueryable()

is plainly rubbish and would never compile - it is however an indication of the direction I was thinking .

Even if I got a foreach to work like that or similar it would break deferred execution

At this point there are around 300,000 foo entities which I will eventualy filter to 5 or 6 foo's - this is why deferred execution is needed.

View 1 Replies

Choosing Persistence Engine - Criterion And Projection?

Jan 24, 2011

I touched on this last year sometime, but I was frustrated at the time and might not have made much sense. I'd like to try again to see if I can get some constructive advice. I am having an issue in choosing a persistence engine. My first choice is FluentNHibernate / NHibernate. However, I am having severe difficulties with their criterion and projection mechanisms. Searching for examples is difficult and when I do find something, I really don't understand what I'm looking at. After a year of trying to bring this together, it still eludes me. I know I could just ask here for help with certain things, but you guys have more things to do than sit and teach me nhibernate criterion. My second choice is Entity Framework 4. I am leaving the CTP 5 off the list for now as there is a major bug in how self-referencing tables are handled at the moment. Now, I have two sub-choices here. The first involves using code first by turning off code generation in the designer and place my enities and edmx in separate libraries (.Domain and .Persistence.Mapping) but this involves a bit of extra work. Then again, for simplicities sake, I could just dump the edmx designer right in the domain library. But this means having the mapping info in the domain library. Not ideal, but it'd work. I still retain the ability to map collections, references and properties as protected or private, and add logic-checking accessors to the entities, as well as setting a protected and public constructor. The entities would still be strong, valid business entities. With these points in mind, what direction should I head?

View 11 Replies

C# - How To Convert Linq To SQL To Linq Entity

Sep 4, 2010

I have the code below could to rewrite from LINq to SQL to Linq to Entity.

[code].....

View 1 Replies

ADO.NET :: Convert LINQ To Int?

Jun 30, 2010

var query = from p in dc.Patients
select p.PAge;

Can i get PAge value in an any int like....

int PAge = query.Single();
I'm trying Convert.ToInt32(-----------------)

but this give me Error on run time

View 1 Replies

ADO.NET :: Convert The Where Clause To Linq?

Oct 22, 2010

how do you convert the WHERE clause of this statement to Linq ?

View 1 Replies

ADO.NET :: Convert Sql Query In Linq?

Oct 2, 2010

how convert this sql query in linq,

SELECT COUNT(AdvisorID) AS AdvisorRegisterLast2Days FROM ob_Advisor WHERE CONVERT(varchar,CreationDate,101) BETWEEN CONVERT(varchar,DATEADD(day,-4,DATEADD(day,2,GETDATE())),101) AND CONVERT(varchar,GETDATE(),101)

View 1 Replies

DataSource Controls :: How To Convert To Linq (vb.net)

Sep 16, 2010

I have an sql statement I want to convert to LINQ (VB.Net).

View 2 Replies

ADO.NET :: Convert From Linq.IQueryable To DataTable?

Aug 23, 2010

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

View 2 Replies

ADO.NET :: How To Convert Bool Value Into String In LINQ

Dec 29, 2010

I have the following query in which I have to convert the 'bool' valu into 'string' value as "Y" or "N". I have a class defined called ChartDosCodeInfoStruct which definesQAIndicator as String. The value I am feteching from DB is a bool value. I need to take this bool value and accordingly assignQAIndicator= "Y" or "N".

UserManager userManager = (UserManager)BaseEntityManager<DataAccessLayer.User>.GetSingleInstance();
List<User> user = userManager.GetCodersForChart(_currentChart.ChartId);
UIConfigurationObject.CoderForChart.value = user.First().FullName.ToString();
[code]...

View 2 Replies

ADO.NET :: How To Convert A Linq Query To A Datatable

Feb 23, 2011

how to convert a linq query to a datatable

this is my query

[Code]....

View 4 Replies

ADO.NET :: Convert Procedure With Datareader To LINQ?

Aug 3, 2010

i have this procedure:

[Code]....

the difficulties are the follows:

1)i cannot know how to execute stored procedure with LINQ

2)how can i set value to my properties after a selection?

3)how can i set optional parameters in a stored procedure by LINQ?

View 1 Replies

Convert Linq Code To Dotnet 2.0?

Mar 17, 2011

string pdfpath = Server.MapPath("images");
string imagepath = Server.MapPath("Images");
using (Stream inputPdfStream = new FileStream(pdfpath + "\NLI_Filled_out.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream inputImageStream = new FileStream(imagepath + "\sign2.gif", FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream outputPdfStream = new FileStream(pdfpath + "\NLI_Filled_output.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
var reader = new PdfReader(inputPdfStream);
var stamper = new PdfStamper(reader, outputPdfStream);
var pdfContentByte = stamper.GetOverContent(3);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
image.ScalePercent(24f);
image.SetAbsolutePosition(100, 130);
pdfContentByte.AddImage(image);
stamper.Close();
}

I have the above code in 3.5 using linq..i want to convert it into dotnet 2.0..

View 1 Replies

DataSource Controls :: Convert SQL To Linq?

Jun 24, 2010

SELECT *
FROM dc.accounts t1
INNER JOIN dc.profiles t2 ON t1.AccountID = t2.AccountID
WHERE EXISTS
(
SELECT *
FROM dc.profileblocks t3
WHERE t3.AccountID = '14' and t1.AccountID = t3.AccountID
)

View 3 Replies

DataSource Controls :: How To Convert Sql Query To LINQ

Feb 13, 2010

How can I convert this sql query to LINQ ?

[code]...

View 1 Replies

ADO.NET :: Cannot Convert String To Bool Error In LINQ

Oct 22, 2010

cannot convert string to bool error in LINQthis is my code:

[Code]....

View 4 Replies

DataSource Controls :: Convert Code Of SQL To Linq?

May 14, 2010

I would like to ask the programmers to help me in C# with LINQ to SQL.

I have this code conn.Open();

SqlDataReader dr = DB.ExecSpReader("select AttachmentName from AttachmentTable where TicketId=" + ticketID, param);

while (dr.Read())

{[code]....

and I need to convert it to LINQ SQL.

View 4 Replies

DataSource Controls :: Convert ObjectQuery To LINQ?

Mar 1, 2010

I like to think I know my way around eSQL, but I'm pretty ignorant when it comes to LINQ. Can anyone tell me how I would write the following ObjectQuery in LINQ?

[Code]....

There is a many-to-many association between Countries and Sponsorships (a Country may have many Sponsorships, and a Sponsorship may have many Countries). I want to find all Countries related to a specific Sponsorship based on the Sponsorship primary key.

View 6 Replies

Convert Linq ISingleResult Output To Datatable?

Apr 4, 2011

I call a stored procedure using linq. I want to convert the ISingleResult output to datatable. what can I do?

DataClassesDataContext Dac = new DataClassesDataContext();
var ExitResult = Dac.Retrieverelations(WorkshopCode);

now I'm using below code for converting but I need a better solution.

D
dataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(Int64));[code]....

View 1 Replies

C# - Convert Foreach Loop To Linq (in Datagridview)

Jul 21, 2010

foreach (GridViewRow row in gridView.Rows)
{ // Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("SuburbSelector");[code]....

I tried the following and got error

Linq:

var Str = SuburbGridView.Rows.Cast<GridViewRow>().Where(r=>(CheckBox)r.FindControl("SuburbSelector")==checked);

Error:

Delegate 'System.Func < System.Web.UI.WebControls.GridViewRow,int,bool>' does not take 1 arguments

View 3 Replies

DataSource Controls :: Convert LINQ Singleresult Set To DataTable?

Jun 10, 2010

I have store procedure which return result set. I have used LINQ datacontext object to get the result set from this store procedure, which returns the result set in IsingleResult format.I bind this IsingleResult to my gridview.

I want to convert this IsingleResult into DataTable format so I can sort the gridview.

View 5 Replies

ADO.NET :: Error - Can't Implicitly Convert Type 'System.Linq.Iqueryable

Aug 25, 2010

If I have below code, how to make it work as it has below compile error:

Error: cannot implicitly convert type 'System.Linq.Iqueryable<system.data.DataSet> to 'System.Data.Dateset'. An explicit conversion exists.

public DataSet GetProductList()
{
using (var sdatabase = new DatabaseDataContext())
{
IQueryable<DataSet> result = wmsdatabase.ExecuteQuery<DataSet>(@"SELECT productid, productname from product group by productid, productname").AsQueryable();
return result; // Compile error here
}
}

View 1 Replies

DataSource Controls :: Convert Linq Query Into IEnumerable DataRows?

May 19, 2010

IEnumerable<DataRow> query = (from obj1 in objeDC.tmpPolicyRenewals.AsEnumerable()
where obj1.AgentCode == "Admin"
select new
{
obj1.Product,
obj1.PolicyNo,
obj1.Insured,
obj1.EffDate,
obj1.ExpDate,
obj1.GrossPrem,
obj1.Status
}) as IEnumerable<DataRow>;

Getting null value. whats error ?

View 2 Replies

Cannot Convert From 'System.Data.Linq.Binary' To 'System.IO.BinaryReader'

Aug 20, 2010

my table column is:

AttachContent varbinary (max)

when i try to retrieve the data and i get this below error, i am using linq

cannot convert from 'System.Data.Linq.Binary' to 'System.IO.BinaryReader'

View 1 Replies

DataSource Controls :: How To Convert Sql Query Into Linq Query

Mar 10, 2010

select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved