ADO.NET :: Order By A Field In Dictionary Using Linq Expression?

Aug 16, 2010

I have an Entity class which has a Dictionary of fields called Data. Now I want to sort Entities by a field in Data. I was able to verify the Linq expression for using fields in a dictionary as e.Data["UserId"] as this seemed to work perfectly when I used LINQ to Objects. e.g. Entities.OrderBy(e => e.Data["UserId"])

However this same expression does not generate the correct NHibernate criteria and errors out finally with a NullReferenceException for propertyName at Hibernate.Loader.Criteria.CriteriaQueryTranslator.GetEntityName(ICriteria subcriteria, String propertyName)in CriteriaQueryTranslator.cs: line 541.

On debugging through NHibernate code, I figured that NHibernate.Linq.Visitors.MemberNameVisitor.GetMemberName(ICriteria rootCriteria, Expression expr) returns a null string in place of the field name after visiting expr using its visitor. This seems to be the cause of grief. I am using an older version of NHibernate (2.1). Are there any limitations in the NHibernate Linq visitor I should be aware of?

View 1 Replies


Similar Messages:

C# - Linq Expression To Return A List Of Strings Based On Field Count?

Nov 11, 2010

Say I have a table Comments with these columns: Id, Comment, Category, CreatedDate, CommenterIdI want to get the top 5 categories from the Comments table (based on the count of each category in that table). How can I do this in linq, to return either List or IQueryable?

View 2 Replies

Sort Or Order Dictionary By Value?

Mar 5, 2011

I try to sort a dictionary with no success

this code i wrote
var sortedDict = _GrandTotalUserDictionary.OrderBy(key => key.Value.Priority);
the dictionary looks like
"key1", new OrderItem(){title:'a', priority:1}
"key2", new OrderItem(){title:'b', priority:3}
"key3",
new OrderItem(){title:'c', priority:12}

View 2 Replies

DataSource Controls :: Compile In Order To Get The System.Linq.Dynamic Namespace / Dynamic Linq Error

Apr 20, 2010

I've added the Dynamic.cs file to my project and have set it's Build Action = Compile in order to get the System.Linq.Dynamic namespace.

However, when I try to use any of the new code I am getting an ambiguous call error; see below.

[Code]....

View 2 Replies

C# - Static Vs Member Field Revisited / Want To Persist A Large Dictionary Of Strings Inside The Memory?

Feb 18, 2011

I need an advice on piece of functionality that I am ought to implement. The scenario is that we haven an HttpHandler which servers to intercept file uploads. In the handler, I need to persist a large dictionary of strings inside the memory. The dictionary might be as large as 100 entries. I am wondering whether it is safe to store that in a static variable, so that it is not initialized every time instance of the handler is created (there will be a lot of instance for sure). In general, what is the approach in such scenarios. Is it a generally better idea to use static fields, to persist data that will not be changed?

View 5 Replies

ADO.NET :: How To Order An Arraylist With Linq

Sep 9, 2010

Is there a way I can sort this query result in Linq? I'd like to sort in descending order by the .Count parameter:

[Code]....

View 2 Replies

ADO.NET :: How To Use LINQ In Order To Filter Out Only Objects

Nov 24, 2010

I have a collection of objects that I want to use LINQ in order to filter out only objects that have properties that meet a certain criteria. I am not big on LINQ so I am not sure how to do this.

I create a basic LINQ statement and get the records this way

Dim lr As IEnumerable(Of LogRecord) = From rr In _logRecords where rr.username="something"

but I only want to add that where condition if someone actually filled in a textbox.

I have other conditions to do the same thing with.

View 5 Replies

ADO.NET :: Linq - Order By Column That Contains Query?

Aug 19, 2010

I got a sql table and is trying to sort the data by the column that contains the data entered in a search form.

My code is below:

[Code]....

View 2 Replies

ADO.NET :: How To Use Order By On The Result Of A LinQ To SQL Query

Dec 8, 2010

How can I use Order by on the result of a LinQ to SQL query ?

I have the following Situation:

Dim ret As New Object

ret = From status In tableStatus _
Select status.STATUS_ID, _
Text = Function_GetText(status.TEXT_ID)

Now I have to order this result on the field Text, has anyone an idea? (I can't use in my case Orde by Function_GetText(status.TEXT_ID))

View 3 Replies

VS 2013 - Linq Order By Not Working

Jan 13, 2015

i use below code

HTML Code:
(From r In tblRoles
Join m In module_master On m.module_id Equals r.module_id
Where Not r.role_name.ToUpper.Contains("OWNER") And Not r.role_name.ToUpper.Contains("CLIENT")
Order By m.module_name, r.role_name
Select r.module_id, m.module_name ,r.role_name
).Distinct
and output is

[code]....

but when i remove distinct then order by works properly..???

View 4 Replies

C# - Static Methods Updating A Dictionary<T,U> Is It Safe To Lock() On The Dictionary Itself

Dec 23, 2010

I have a class that maintains a static dictionary of cached lookup results from my domain controller - users' given names and e-mails.My code looks something like:

private static Dictionary<string, string> emailCache = new Dictionary<string, string>();
protected string GetUserEmail(string accountName)
{
if (emailCache.ContainsKey(accountName))
{
return(emailCache[accountName]);
}
lock(/* something */)
{
if (emailCache.ContainsKey(accountName))
[code]...

View 6 Replies

C# - Order By Descending Is Not Working On LINQ To Entity?

Apr 15, 2010

Order by descending is not working on LINQ to Entity In the following Query In place of ascending If I keep descending it is not working.

[code]....

View 1 Replies

Get Info About Http Post Field Order?

May 17, 2010

Is it possible to get information about post field order in ASP.NET? I need to know whether some field was the last one or not.

I know I can do it through Request.InputStream, but I'm looking for a more high level solution without manually stream parsing.

Generally I'm doing testing of http post sent by my application and there is no practical usage for this in ASP.NET.

View 1 Replies

DataSource Controls :: Order By Count And Group By In LINQ?

Mar 14, 2010

How do I translate the following query into LINQ to SQL?

[Code]....

View 1 Replies

ADO.NET :: Use An Expression On A Linq Outer Join?

Nov 18, 2010

private void GetResults()

Use an Expression on a Linq Outer Join

View 1 Replies

Regular Expression For Password Field?

Nov 24, 2010

i want regular expression for my password field 1. which will not allow to enter two same consecutive charcters 2. it should contain min 8 charcters.3. should contain atleast 2 numeric charcters and if possible code for not allowing user to enter comman passwords

View 2 Replies

Web Forms :: Required Field Validator Firing In Wrong Order?

Feb 1, 2010

I have a web page which contains 3 drop down boxes followed by 3 textboxes. I am implementing Required field validators for all of them . But when i hit submit , The Page first checks for empty Textboxes before checking for any value in Drop down boxes , but i want the Drop down boxes to be validated first before Textboxes. How Can it be achieved?

View 1 Replies

C# - Order Datatable By Relevance Using Linq By Column Values Which Are Comma Sperated?

Aug 31, 2010

I have a Datatable that contains a column called Tags, Tags can have values such as

row[0] = Tag1
row[1] = Tag1, Tag2
row[2] = Tag2, Tag3
row[3] = Tag1, Tag2, Tag3
row[4] = Tag4, Tag6

and are seperated by comma's etc..

I have the value of Tags for the current document and have run a query to select all other documents that have either of the Tags in there row. for example lets say the current document Tags are (Tag1, Tag2, Tag3)

so from the example rows above all the rows above are returned apart from row[4] Here is the bit i'm lost with, i now want to sort the datatable by how many tags are matched with the current document. so for the example i've talked about so far they should be ordered

row[3] = Tag1, Tag2, Tag3
row[1] = Tag1, Tag2
row[2] = Tag2, Tag3
row[0] = Tag1


Not used linq before but was told it could do this. so far i have

var query = from c in dt.AsEnumerable()
orderby c.Field<string>("Tags").CompareTo(dr["Tags"]) ascending
select c;

View 3 Replies

SQL Reporting :: Correct The Expression Of The Textbox Field?

Nov 16, 2010

i've written the code in expression field...

=format(sum(fields!salary.value),"##,##,##,##,##,##,##0.00")

the code is for printing the number in this format(12,23,23,34,123.00)

now i got an problem i.e if i give 5 digit the it will print ,,,,,12,123.00 the remaining commas

are printed.. i dont want to print the extra commas.. how the word length is there that much it

should take..i.e( for 5 digit 12,123.00 and for 9 digit 12,23,23,123.00)...

i've tried by removing some of the #'s but it is for fixed number..

View 3 Replies

SQL Reporting :: Writnig The Field Expression In SSRS

Apr 14, 2010

writting the following Field Expression in SSRS

View 2 Replies

C# - Order A List Of Entities Based On A Field From A Separate Entity With A Relationship

Mar 6, 2011

I'm using Entity Framework for my object-relational mapping, and jqGrid for my grid.

I have an Employee entity, that contains a ContactID field. I have a Contact entity that contains fields FirstName and LastName.

I want to display a list of Employees in a grid, and give the user the ability to sort by FirstName and LastName.

Here's what I have right now:

public JsonResult GridData(string sidx, string sord, int page, int rows)
{
var pageIndex = Convert.ToInt32(page) - 1;
var pageSize = rows;
var totalRecords = GetAllEmployees().Count();
var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);
IQueryable<Employee> employees = GetAllEmployees().
OrderBy(sidx + " " + sord).
Skip(pageIndex * pageSize).
Take(pageSize).ToArray();
}

As you can see, this only gives me the ability to sort by fields in the Employee entity, so I can't sort by FirstName and LastName.

How can I modify this to accomplish that?

View 1 Replies

DataSource Controls :: Linq To Sql Query / Could Not Translate Expression?

Mar 26, 2010

I have the following LINQ query which works correctly:

[Code]....

The following query, however causes an error:

[Code]....

"Could not translate expression 'Table(t_f2f_event).Where(e => ((e.EVT_START_DATE > Invoke(value(System.Func`1[System.Nullable`1[System.DateTime]]))) && (e.EVT_START_DATE < Invoke(value(System.Func`1[System.Nullable`1[System.DateTime]])))))' into SQL
and could not treat it as a local expression."

View 2 Replies

C# - Pass Parameters To LINQ To XML Query By Using Lambda Expression?

Aug 17, 2010

I am new to LINQ to XML in .net(C#, asp.net). I want to know more about Lambda expressions. I am using Lambada expression with the following query.

count = FieldRoot.Element("USER").Element("MM")
.Descendants("MMMS")
.Where(a => a.Attribute("ID").Value == MID)
.SelectMany(b => b.Descendants("ABC")).Count();

how the Lambda expression work specially in case of parameters (in the above case a & b) ? What is the basic concept of parameters in Lambda expression ? Can we use the names of the variables defined outside of the query instead of a & b ? which elements a & b represent in the above case represent ? Can we pass parameters from outside in the query ? If we can pass parameters from outside query then how it will be done? If you give me any other example instead of the above query to understand the concept of parameter in Lambda expression.

View 1 Replies

ADO.NET :: Added Tables Apply Linq To Sql Expression But Error ?

Apr 1, 2011

I have created an Entity Model (.edmx) file with MySql database.I added some tables and then try to apply some linq to sql expression but for each expression it thorws an error "Object Reference not set to an instance of the object"

[Code]....

whichever function I call, I get the same error : Object Reference not set to an instance of an object.

View 5 Replies

MVC :: Create A DraftResult Class In Order To Show Data That Resides In Two Different Tables Using Linq

Aug 9, 2010

The problem is I had to create a draftResult class in order to show data that resides in two different tables using linq which means if i want to add or remove a column i will need to do so in the draftresult and in my linq. Here's what my setup looks like: I have two tables (draft, lookUpStatus)

draft table columns
idname,status id
lookupStatus
idtitle
public class draftResult {
public string draftName {get; set;}
public string status {get; set;}
}

I want to list the draft name and the status title in a table view. In order to do this, I wrote the following linq in a method in my sqlRepository class and return it to a IQueryable<draftResult>. My controller instanstiates the sqlRepository object and invokes GetDraftListing().

public class sqlRepository {
private Table<Draft> _draft;
private Table<LookUpStatus> _lookupubStatus;
public IQueryable<draftResult> GetDrafLtisting() {
return (from draft in _draft
join status in _lookuptatus
on draft.StatusID equals status.ID
select new draftResult
{
draftName = draft.name,
status = status.Title
});
}
}

The above process works but does not seem as flexible and i'm trying to get a better understanding of MVC and LINQ.

View 8 Replies







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