ADO.NET :: Build A Linq Query / Linq Random Selection?

Sep 14, 2010

I've build a linq query.But i want a random selection so its not always ID : 1,2,3,4,5,6 How can i randomize this var? I like to bind it to a repeater.//TagCloud:

Random rand = new Random();
var tc1 = from i in JumpTide.cms.menu.GetMenuItems(32)
select new

[code]...

View 1 Replies


Similar Messages:

DataSource Controls :: Random Results From A LINQ To SQL Query?

Jan 23, 2010

I have this LINQ query:

var agnts = (from a in db.agents select new { a.userid, a.name }).Take(10);

How can I get randomly get 10 records from my agents table?

I have tried:

agnts = agnts.OrderBy(n => Guid.NewGuid());

but this doesn't seem to do anything.

View 5 Replies

Forms Data Controls :: Sql To Linq Query / Looking To Translate An SQL Query Into Linq?

May 28, 2010

I'm looking to translate an SQL query into linq

INNER JOIN Usrs ON
SAQ.UserId =
Usrs.UserId AND Scan.UserId =
Users.UserId

I'm not sure how to include the "AND" in the LINQ statement.

View 3 Replies

ADO.NET :: Dynamic LINQ Query / Use "if Statement" In Linq Query

Feb 11, 2011

I want to use "if statement" in Linq query. How can I do this situation?

For example:

if txtAge.Text=="", I will not use that in Linq Query.

else txtAge.Text!="", I will use that in Linq Query.

View 8 Replies

C# - How To Pull A Random And Unique Record From SQL Via LINQ

Apr 23, 2010

how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RANDOM item from the database that the user has not seen before.

The data I am pulling from the database is very small. Is there any way I can just hit the database once for 1000 records and then randomly scroll through those?

Should I put a cookie on the users system recording the IDs of which items they have seen, pull a random record, check to see if it is seen and if so, pull from the database again? That seems like performance issues just waiting to happen.

View 1 Replies

Using .net MVC With Sharp Architecture - Looking For Linq Orderby Random

Jul 26, 2010

i'm using Asp.net MVC with Sharp Architecture.

I have this code:

return _repositoryKeyWord.FindAll(x => x.Category.Id == idCAtegory)
.Take(50).ToList();


How can i order by random?

Note: i don't want to order the 50 extracted items, i want order before and then extract 50 items.

View 6 Replies

'Random' Orderby In Webservice Using LINQ To Entities?

Jun 1, 2010

Now I know there is a reason to this odering but my tiny little brain can't get my head around it.I am using a webservice to pull through data to a webp[age and have the following that is so far pulling data through from UUF1:

public string[] GetBuyer(string Memberkey)
{
try

[code]...

View 2 Replies

ADO.NET :: How To Build Dynamic Linq To SQL Queries

Nov 7, 2010

I'm trying to do something that on the face of it is very simple.

If I have 5 text boxes, and 1 of them is blank, I want to exclude that textbox from the query, rather than searching for where a field is blank.

I've tried to do a bit of research into dynamic linq queries, but have come up empty handed, or what I've found doesn't seem to quite answer my question.

View 3 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

Linq Query Returning Less Records Than Sql Query?

Mar 19, 2011

I am facing a big problem with simple linq query.. I am using EF 4.0..

I am trying to take all the records from a table using a linq query:

var result = context.tablename.select(x=>x);

This results in less rows than the normal sql query which is select * from tablename;

This table has more than 5 tables as child objects (foreign key relations: one to one and one to many etc)..

This result variable after executing that linq statement returns records with all child object values without doing a include statement.. I don't know is it a default behavior of EF 4.0 . I tried this statement in linqpad also..but there is no use... But interesting thing is if I do a join on the same table with another one table is working same is sql inner join and count is same..but I don't know why is it acting differently with that table only.. Is it doing inner joins with all child tables before returning the all records of that parent table?

View 2 Replies

Linq Query - How To Select Inner Query Into List

Oct 17, 2010

I am writing a linq query to select a blogpost,

[code]....

The blogpost i am testing got 3 tags attached to it. The table structure is:

(table)BlogPost -> (table)BlogPostTags <- (table)Tags

So the BlogPostTags table only contains 2 fields, BlogPostID and TagID.

When i run the query above i get 3 results back. Same blogpost 3 times but with 1 tag in each. It should return 1 post with 3 tags. The problem lies in the Tags query above.

View 1 Replies

ADO.NET :: IN Query, Linq To Sql?

Aug 2, 2010

I have a list which contains few email ids

List<string> EmailId= { ....}
Now I have a db table Users. I need to select all users whose email exist in the above list. In sql we could write "where emailid in ('email1', email2' ,...)"

how to do this in linq to sqlquerable<Users> existingUsers = Users.getTable().where (u=>u.emailaddress in EmailId). I want to do some thing similar

View 2 Replies

ADO.NET :: Not Sure How To Do This Query In Linq To Sql

Sep 12, 2010

I need to figure out how to express this in linq to sql:I have one or more records that contain what is essentially a wildcard sql parameter, like '100_-___-2', which should match 100[any 1 char]-[any 1 char][any 1 char][any 1 char]-2, for example. Each login will have one or more of these 'datamasks' associated with it.I need to write a query in linq to sql that does something like:

select * from something
where fieldA = 'someValue' or fieldB = 'someValue'

so far, simple, but I also need to restrict the returned records to only those that match the user's 'datamasks'. I'm not sure exactly how to translate this to linq to sql... here is what a working query *without* the datamasks part looks like:

[Code]....

I need to tack on the datamasks part... can I do it right there in the same statement? or do I need to do a foreach loop on the datamasks records and append a new && condition for each one? hmmm... just thought of that as I was writing this.. I'll try that out. But I'm posting this anyway for more input... I guess that would look something like:

foreach (string mask in datamasks)
{
query = query.Where(item =>
System.Data.Linq.SqlClient.SqlMethods.Like(item.AccountNum, mask));
}

would that work? would each additional 'where' condition be 'appended' to the existing query definition?

View 3 Replies

Many To Many LINQ TO SQL Query

Mar 11, 2010

Users
Roles
UserRoles
MenuItems
RoleMenuItems

A User can have multiple Roles and a MenuItem can be accessed by multiple Roles. Now I want to write a method as follows:

public IList<MenuItems> GetMenuItems(UserRoles userRoles)
{
var menus = // LINQ query to get the MenuItems by UserRoles
return menus.ToList();

View 1 Replies

ADO.NET :: How To Use Linq Query Union

Aug 31, 2010

I need to use Union for below Linq queries. I could use Union it if it was simple "select new whith{" but Now that I Specified Class, I encounter Error using union

[Code]....

View 3 Replies

Need To Use The Like Operator In A Linq Query?

Apr 28, 2010

i need to use the like operator in a linq queryfor this:

timb = time.Timbratures.Include("Anagrafica_Dipendente")
.Where(p => p.Anagrafica_Dipendente.Cognome + " " + p.Anagrafica_Dipendente.Nome like "%ci%");

View 2 Replies

.net - LINQ-Query Is Not Working?

Dec 13, 2010

Table User (UserID, Username)
Table Admin (AdminID, Username)
Table PM (PMID, SenderID, Sendertype, RecipientID, RecipientType)
Get all Information from PM
if SenderType == 'A' join SenderID to Admin-Table, get Username
if SenderType == 'U' join SenderID to User-Table, get Username
if RecipientType == 'A' join RecipientID to Admin-Table, get Username
if RecipientType == 'U' join RecipientID to User-Table, Get Username

someone have an Idea how to solve in 1 query?

View 3 Replies

Possible To Do A Linq Query On A GridView ?

Sep 13, 2010

I have a datakey that I'd like to query from my GridView instead of looping through all the rows and comparing the key of each row. So I was wondering if it was possible to just do a linq query on the gridview (not datatable) and filter with the datakey.

View 4 Replies

Way To Filter LINQ Query

Feb 17, 2011

I need to filter LINQ query using comboboxes and textboxes. The problem is I can't manage to get the result and I always get the empty gridview (used for showing filtered data). Can anyone help me why am I getting no results at all? I've checked the debugger and the data sent to query is valid, although, I'm not sure about "string.Empty" value.

string naziv, nazivEn, adresa, tel, fax, mob, email, web, oib, tip, mjesto;
if (chkMjesto.Checked == true)
{
mjesto = cbMjesto.SelectedItem.Text;
}
[code]....

View 2 Replies

.net - Linq And SQL Query Comparison

Apr 4, 2011

SELECT Sum(ABS([Minimum Installment])) AS SumOfMonthlyPayments FROM tblAccount
INNER JOIN tblAccountOwner ON tblAccount.[Creditor Registry ID] = tblAccountOwner.
[Creditor Registry ID] AND tblAccount.[Account No] = tblAccountOwner.[Account No]
WHERE (tblAccountOwner.[Account Owner Registry ID] = 731752693037116688)
AND (tblAccount.[Account Type] NOT IN
('CA00', 'CA01', 'CA03', 'CA04', 'CA02', 'PA00', 'PA01', 'PA02', 'PA03', 'PA04'))
AND (DATEDIFF(mm, tblAccount.[State Change Date], GETDATE()) <=
4 OR tblAccount.[State Change Date] IS NULL)
AND ((tblAccount.[Account Type] IN ('CL10','CL11','PL10','PL11')) OR
CONTAINS(tblAccount.[Account Type], 'Mortgage')) AND (tblAccount.[Account Status ID] <> 999)
[code]....

View 4 Replies

C# - Test If Linq Query Went Through?

Mar 15, 2011

This is my code from my controller:

MGEntities db = new MGEntities();
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
MembershipUser myObject = Membership.GetUser();
Guid UserID = (Guid)myObject.ProviderUserKey;
MyProfile profile = new MyProfile();
profile.Address = model.Address;
profile.City = model.City;
profile.Zip = model.Zip;
profile.State = model.State;
profile.UserId = UserID;
Debug.Write(profile.State);
db.aspnet_Profiles.Add(profile);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}

This is my MyProfile Class:

namespace MatchGaming.Models
{
[Bind(Exclude = "ProfileId")]
public class MyProfile
{
[Key]
[ScaffoldColumn(false)]
public int ProfileId { get; set; }
public Guid UserId { get; set; }
[DisplayName("Address")]
public string Address { get; set; }
[DisplayName("City")]
public string City { get; set; }
[DisplayName("Zip")]
public string Zip { get; set; }
[DisplayName("State")]
public string State { get; set; }
}
}

After the linq query is executed, i check my database and nothing is added. I am using POCO for my entities. Here is my class:

namespace MatchGaming.Models
{
public class MGEntities : DbContext
{
public DbSet<MyProfile> aspnet_Profiles { get; set; }
}
}

View 2 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

C# - Set A Value On A Linq Object During The Query?

Feb 16, 2010

I have a simple query i.e.

var trips = from t in ctx.Trips
select t;

The problem is that I have an extra property on the Trip object that needs to be assigned, preferably without iterating through the returned IQueryable.

Does anyone know how to set the value during the query? (i.e. select t, t.property = "value")

View 3 Replies

C# - Get The Sql Created By A Linq Query?

Jan 18, 2010

I've been developing a ASP.NET page and have been using LINQ to handle talking to MS SQL server. I'm ok at basic SQL, however I'm a lot better with designing queries using LINQ. I know they are similar but I find it easer to design complex queries in LINQ. My question is this: Is there a way to design a query in LINQ and then get the SQL that it generated? I would like to embed the SQL in a stored procedure since multiple pages (outside my control) will need to do the same query.

View 4 Replies

ADO.NET :: Linq Query With Ordering?

Jan 28, 2011

the best way to do the following (I'm using a simplified example of my actual problem?Say I have a customer ordered items table with fields: oItemId, OrderId, ProductId, ItemPriceI want to query where OrderId >oMin && OrderId <oMaxand for each value of OrderId I want to find the record with the highest ItemPriceso for a single OrderId the query would be:(from o in context.orderItems where OrderId==x orderby o.ItemPrice select o).first()but OrderId isn't a single value. If I modify the where clause then this query would still produce a single record whereas I want a single record per OrderId.oh and as an additional question: does anyone have a compact test for whether a record exists. I am using the querystring to specify an Id and there are numerous things that I want to protect against. If I do:

var myRecord = from o in context.orders where o.orderId == request.querystring["Order"] select othen this fails if the querystring isn't specified. So first I test that the querystring != nul . Then I need to do:bool recordExists = (myRecord != null)because even if the querystring is specified it may be an invalid orderId and thus the query returns no results. Is there a shorter/simpler way to calculate the result. I have not yet got to grips with lambda expressions and I'm not sure whether there is a better approach with lambda expressions.

View 2 Replies







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