public List<Store> GetAllFriendsTopStores(long uid, List<long> users)
{
using (var entities = new myEntities()) {
var v = entities.DbUsers
.Where( x => users.Contains( x.uid ))
.Stores // i can't select stores here? Why is this???
}
}
In this case Stores is a navigation property... I need to be ...
I have a bunch of Linq to Entity methods that had the same select statement, so I thought I would be clever and separate that out into it's own method to reduce redundancy... but when i attempted to run the code, i got the following error...
this method cannot be translated into
a store expression
Here is the method i created...
...
I'm having a list of string
List<String> MyList=new List<String>{ "A,B" , "C,D,E" , "F,G" };
I need to convert the List "MyList" into the following format
"A-B"
"B-A"
"C-D"
"C-E"
"D-C"
"D-E"
"E-C"
"E-D"
"F-G"
"G-F"
Now i'm using something like spliting each item by "," and then adding that to a new list, then taking combination and...
The query
var q = from elem in collection
where someCondition(elem)
select elem;
translates to
var q = collection.Where(elem => someCondition(elem));
Is there a LINQ syntax that would translate to the following?
var q = collection.Where((elem, index) => someCondition(elem, index));
...
I'm having a List of String like
List<string> MyList = new List<string>
{
"A-B",
"B-A",
"C-D",
"C-E",
"D-C",
"D-E",
"E-C",
"E-D",
"F-G",
"G-F"
};
I need to remove duplicate from the List i.e, if "A-B" and "B-A" exist then i need to keep only "A-B" (First entry)
So the result will be like
...
Hi everyone,
Let say we have a class
Category
{
ID,
Name,
ParentID
}
and a List
1, 'Item 1', 0
2, 'Item 2', 0
3, 'Item 3', 0
4, 'Item 1.1', 1
5, 'Item 3.1', 3
6, 'Item 1.1.1', 4
7, 'Item 2.1', 2
Can we using LINQ to render a tree like:
Item 1
Item 1.1
Item 1.1.1
Item 2
Item 2.1
Item 3
Item 3.1
Any helps is appreci...
Caveat: This might be an inappropriate use of C#'s dynamic keyword and I probably should be using a strongly-typed view model, but...
I'm trying to avoid creating a strongly-typed view model by passing a C# 4 dynamic type to my view. I have this in my controller:
public ActionResult Index()
{
var query =
fro...
I have something like this:
long[] f = new long[4]{1,10,100,1000};
I want to divide 1000 by 100, 100 by 10 and 10 by 1
Is there a way to return results in an array with the results eg/ 10,10,10
UPDATE: This seems to confuse a few so here is another example
long[] f = new long[3]{1,2,6};
I want to divide 6 by 2 and 2 by 1 with the ...
Lets assume we have the following array
var arr = new string[] {"foo","bar","jar","\r","a","b,"c","\r","x","y","z","\r");
Also ignore the fact that this is strings, so no string hack solutions please.
I want to group these elements by each "\r" in the sequence.
That is, I want one array/enumerable with "foo","bar","jar" and another w...
SELECT t_PersonalInformation.personalInformation_Name, t_PersonalInformation.personalInformation_PresentAddress,
t_PersonalInformation.personalInformation_PermanentAddress, t_PersonalInformation.personalInformation_Phone,
t_PersonalInformation.personalInformation_Email,
t_Applicant.appl...
SELECT t_PersonalInformation.personalInformation_Name, t_PersonalInformation.personalInformation_PresentAddress,
t_Applicant.applicant_TotalExperience,
t_Experience.experience_CompanyName,
t_Experience.experience_Responsibilities,
t_Training.training_TitleDetails
FROM t_Applic...
Hi All
I have the following method:
/// <summary>
/// Gets the specified side of trades.
/// </summary>
/// <param name="tradesDictionary">The trades dictionary.</param>
/// <param name="side">The side.</param>
public IEnumerable<TradeRecord> GetTrades(Dictionary<Guid, TradeRecord> tradesDictionary, Side side)
{
return (from tradeR...
Can anyone explain what the difference is between:
tmp = invoices.InvoiceCollection
.OrderBy(sort1 => sort1.InvoiceOwner.LastName)
.OrderBy(sort2 => sort2.InvoiceOwner.FirstName)
.OrderBy(sort3 => sort3.InvoiceID);
and
tmp = invoices.InvoiceCollection
.OrderBy(sort1 => sort1.Inv...
I'm thinking of replacing a lot of inline foreaches with Linq and in so doing will make new methods, e.g.
Current:
foreach(Item in List)
{
Statement1
Statement2
Statement3
}
Idea:
List.Foreach(Item => Method(Item))
Obviously Method() contains Statement1..3
Is this good practise or is calling a method thousands of times...
Folks,
I know LINQ has a SequenceEquals method. This method makes sure each item value in each collection matches, in the same order.
What I'm looking for is a more "Equivalent" type of functionality. Just that both sequences contain the same items, not necessarily in the same order.
For example, nUnit has CollectionAssert.AreEqual(...
I'm trying to figure out a way of querying an object in my datamodel and include only those parameters that are not null. Like below:
public List<Widget> GetWidgets(string cond1, string cond2, string cond3)
{
MyDataContext db = new MyDataContext();
List<Widget> widgets = (from w in db.Widgets
where
...
I'm upgrading a project to .net 4. My GridViews are using DataSets and implement filtering, sorting and paging using an ObjectDataSource.
What is the best practice to connect a GridView to a Linq query and implement sorting, filtering and paging?
Do i still use a DataSet and ObjectDataSource or is there a way to use another type of Da...
I'm supporting a multi-tenant system that allows users to define custom forms. The data model is EAV based because issuing dynamic DDL to change table schema doesn't work when supporting multiple tenants in a single DB. An upcoming requirement is to build a flexible query designer that allows users to setup simple predicates against th...
I'm looking for a way to compute the range of a give set of number for example.
if I had H555,H567,H589,H590,H591,H592,H593,H594,H595,H596,H597
I would like output of H555,H567,H589-H597.
I have looked through relevant questions and can not find anything like what I'm looking for.
Thanks
...
Is there such a thing?!
So for eample, on my image load I have the following hooked up to a table where "Image" is a binary image set of data.
protected void Image1_Load1(object sender, EventArgs e)
{
myent logo = new myent();
var query = (from p in logo.tblLogoes
where p.Id == id && p.Id2 == ...