Consider these two structures:
struct Task
{
public Int32 Id;
public String Name;
public List<Registration> Registrations;
}
struct Registration
{
public Int32 Id;
public Int32 TaskId;
public String Comment;
public Double Hours;
}
I am selecting a bunch of entries in a DataTable into new structures, like s...
Hi all,
I have some problems in executing a Linq query with the group by clause in a C# project.
Here following the query:
var items = (
from controlForm in dataContext.ControlForms
join controlFormStatus
in dataContext.ControlFormStatus
on controlForm.FK_ControlFormStatus equals controlFormStatus.Id
...
This is the scenario. I have the following three classes, they are defined in Entity Framework, i only define them here for the example:
public class Foo
{
public string Color { get; set; }
}
public class Bar : Foo
{
public string Height { get; set; }
}
public class Pipe : Foo
{
public string Width { get; set; }
}
So, I have m...
I have an :
ObservableCollection<X> x_collection = new ObservableCollection();
public class X
{
public X()
{
Items = new ObservableCollection<Y>();
for(int i = 0; i < 10; i++)
{
Items.Add(new Y(i % 2 == 0));
}
}
public ObservableCollection<Y> Items {get; set;}
}
publi...
Hello,
I have this simple piece of code
public ActionResult ListToGrid(string field, string direction)
{
_model.MyList = _repo.List();
}
To sort, I can do this :
_model.MyList = _employeeService.List().OrderBy(x => x.FirstName).ToList<Employee>();
But I'd like use "as field" the name receive (field) in argument and the directi...
Hi all!
I have to calculate the percentage in the group by clause.
More in depth I need to calculate the percentage of ControlForms that have Status = 'False'. The Status is in the table checkResult.
var items = (from controlForm in dataContext.ControlForms
join controlFormStatus in dataContext.ControlFormStatus on controlF...
from f in db.Table1
orderby Guid.NewGuid()
select f
this doesn't seem to work. how can i randomize results?
...
List<NastavaIzvjestaj> nastava_izvjestaj = new List<NastavaIzvjestaj>();
var data_context = new DataEvidencijaDataContext();
int pomSum = 0;
var prisustvo = (from j in data_context.nastava_prisustvos
select j.br_indexa).Distinct();
var lista = prisustvo.ToList();
foreach ...
Hi,
When you create a datacontext, its connection is closed until you retrieve objects and it stays open when you retrieve objects in case you use deferred operators or late binding.
Is it possible (in an extension method of the datacontext of not) to force the datacontext to open its Connection without querying LINQ with LINQ or doing...
where can I find the code for GetCustomerList(), GetOrderList() for the LINQ 101 samples
...
Why is it the syntax of the Select property in the LinqDataSource so different from Linq I would write inline in C#? I mean like:
new (Id As MyId, Name As MyName)
vs
new (MyId = Id, MyName = Name)
And the syntax diverges more when you start doing things like concatenation in the projection. I am using this with a Entity Data mode...
Its easy enough to instantiate multiple DataContexts in LINQPad. Is there any way to set these instances to Log to the "SQL" Tab of the results pane?
Setting myDataContext.Log = this.Log doesn't work.
...
I have a linq query that i'd like to get the query syntax for.
var q = customers.Where(x => x.name == "smith");
Is there something like IQueryable.ToQuerySyntaxString()? that would return something like this:
from cust in customers where cust.name
== "smith";
I'm asking because I can construct my query using method syntax, bu...
I would like to offload the work of generating an sql statement from the application to the database. Is this possible?
...
What's the best way to transform an IEnumerable into a lookup- or dictionary-like structure, but with multiple keys per value?
What I'm looking for is something that does roughly the same thing as this, and in a generic way:
var wordsByLetter = new Dictionary<char, HashSet<string>>();
foreach (string word in words)
{
foreach (char l...
I am encountering a very strange issue I wonder if anyone has seen before. I have as part of my Save() method in a repository that it will search out and find each associated tag by it's name. There is a line in there that looks like this.
var tagRepo = (from t in tagRepository.Query() where t.Name == tag.Name select t).SingleOrDefault(...
I have a collection of Points, stored in a PointCollection.
I need the points in the collection to draw lines. So, for example, if a point collection has four points, that will be two lines, as I use pairs of points in the collection to draw the line. I am looking for a way, preferably using linq, and as few lines of code as possible,...
I would like to know to to write most efficient LINQ (EDIT: to Entities) query with a list as a condition. Here is the thing.
Lets say we have the following data structure:
public class Recipe
{
public int Id;
public string Name;
public List<Ingredient> IngredientList;
}
public class Ingredient
{
public int Id;
pub...
Hi
I have a number of related issues but I will break the questions down into seperate posts.
My XML is <Person>.....<Skills><Skill>Resus<Skill></Skills></Person>
My code is :
var products1 = from prd in xDoc.Descendants("Person")
select new BusinessEntityLayer.Personnel
{
PayrollNo = (String)prd.Element("PayrollNumber"),
FirstN...
I have an xml that I am querying. One of the nodes is missing. So when I call XElement.Value I get a null exception.
What is the best way to guard against this? I know I can write an extension method, but I am wondering is there something build into the language for this?
...