linq

Random Name Picker

I have a class which contains 10 names (U1, U2, U3..and so on). I have to choose 5 names everyday, and display one as the Editor and 4 as Contributors While selecting the random names, I have to also consider that if one user is selected as Editor, he cannot become editor again till everyone got their chance. The output should look si...

DataContext to DB

Hi all, I have designed my DB using the ORM in VS 2008. What is the best way to export this to an SQL server so it will create the tables and relations on SQL Server? Thanks, JD ...

How to replace auto-implemented c# get body at runtime or compile time?

I've been trying to figure this out all night, but I guess my knowledge of the .Net Framework just isn't that deep and the problem doesn't exactly Google well, but if I can get a nod in the right direction I'm sure I can implement it, one way or another. I'd like to be able to declare a property decorated with a custom attribute as such...

how to find last version no from a list<> in C#

I have a entity class RenderingTemplates. Inside this i have a property List which holds all versions of rendering template. RenderingTemplateVersion has a property VersionName which stores version name as "Version 1.0". I am creating a new version and want to find last version no.so that i can append it by 1 and make new VersionName as...

MSCRM: How to create entities and set relations using the xRM linq provider

Do I need to save newly created crm entity instances before I can set relations to other crm entity instances? I'm facing the problem that after calling CrmDataContext.SaveChanges() the newly created entities are written to the database, but the relations between those newly created instances are missing in the database. What do I miss...

how to set error message of the independent form in the status bar of the mdi form in c#?

i have one independent form where i am checking read only access of an xml file , if the file is read only then i have to display message in the status bar of MDI form. since i am using independent form to valid xml file, status bar of the MDI form is not displaying the error message. now how to display message? thanx in advance ...

Comparing 2 objects and retrive a list of fields with different values

Hi given a class with 35 fields and 2 objects with a certain number of different fields value. is there an clever way to get a list with the fields name where the objext Say obj1.Name = "aaa"; obj1.LastName = "bbb"; obj1.Address = "xcs"; obj2.Name = "aaa"; obj2.LastName = "ccc"; obj2.Address = "jk"; objective: list containing 2 s...

Deferred execution of List<T> using Linq

Say I have a List<T> with 1000 items in it. Im then passing this to a method that filters this List. As it drops through the various cases (for example there could be 50), List<T> may have upto 50 various Linq Where() operations performed on it. Im interested in this running as quickly as possible. Therefore, i dont want this List<T> f...

why datetime.now not work when I didn't use tolist?

When I use datacontext.News .Where(p => p.status == true) .Where(p => p.date <= DateTime.Now) .ToList(); the system will return no results; When I use datacontext.News .Where(p => p.status == true) .ToList() .Where(p => p.date <= DateTime.Now) .ToList(); system will return expected results. Can anyone t...

DB4o Linq query - How to check for null strings

Hey there - simple query: var q = (from SomeObject o in container where o.SomeInt > 8 && o.SomeString != null //Null Ref here select o; I always get a null reference exception. If I use String.IsNullOrEmpty(o.SomeString) the query takes about 100 times as long, as if I use && o.SomeString != "" (which is way faster, but o...

How can i sort Generic list with Linq?

How can i sort myScriptCellsCount.MyCellsCharactersCount (list int type) in linq public class MyExcelSheetsCells { public List<int> MyCellsCharactersCount { get; set; } public MyExcelSheetsCells() { MyCellsCharactersCount = new List<int>(); } } void ArrangedDataList(DataTabl...

sort Ienumerable list

I have the following list IEnumerable<Car> cars The Car object has a model and a year. I want to sort this list by model and then year (within model) what is the best way of doing this ? ...

How can I use linq to build an object from 1 row of data?

Hi All, I have a quick linq question. I have a stored proc that should return one row of data. I would like to use a lambda to build an object. Here's what I'm currently doing which works, but I know I should be able to use First instead of Select except I can't seem to get the syntax correct. Can anyone straighten me out here? Thanks f...

LINQ extention SelectMany in 3.5 vs 4.0?

Hi When I saw Darins suggestion here .. IEnumerable<Process> processes = new[] { "process1", "process2" } .SelectMany(Process.GetProcessesByName); ( http://stackoverflow.com/questions/3059667/process-getprocessesbyname/3059733#3059733 ) .. I was a bit intrigued and I tried it in VS2008 with .NET 3.5 - and it did not com...

Conditional OrderBy

So, right now I've got a number of columns the user can sort by (Name, County, Active) and that's easy but messy. Looks something like this... Select Case e.SortExpression Case "Name" If (isDescending) Then resultsList.OrderByDescending(Function(a) a.Name).ToList() ...

Sharepoint 2010: Full text plus faceted search over an External Content List using Search Services (or possibly FAST)

I have an External List over a products table in our database. I want to be able to build a search form over it via a full text search; in addition to being able to filter down on properties on my initial search. For example, say I'm looking for DVDs under 10.00 in product DB. I want to be able to have a search box where I enter "DVD OR...

iqueryable select/where not working

I have two tables Boxer and Prospect. Boxers has general stuff like name and and dob etc and a BoxerId While Prospect contains only one value (at the moment) which is a boxerId. If a boxer is a prospect(up and coming boxer) there Id will be in the prospect table. This works fine but now I want to select all boxers that are prospects ...

Use LINQ to count the number of combinations existing in two lists

I'm trying to create a LINQ query (or queries) that count the total number of occurences of a combinations of items in one list that exist in a different list. For example, take the following lists: CartItems DiscountItems ========= ============= AAA AAA AAA ...

C# convert an IOrderedEnumerable<KeyValuePair<string, int>> into a Dictionary<string, int>

I was following the answer to another question, and I got: // itemCounter is a Dictionary<string, int>, and I only want to keep // key/value pairs with the top maxAllowed values if (itemCounter.Count > maxAllowed) { IEnumerable<KeyValuePair<string, int>> sortedDict = from entry in itemCounter orderby entry.Value descending s...

Override Attribute in Partial Class (DBML)

Hi, Is it possible to override an attibute set on a partial class? So I have one autogenerated partial class like this: [Table(Name="dbo.Users")] public partial class MbsUser : INotifyPropertyChanging, INotifyPropertyChanged { This is generated in my DBML. The problem is, I don't want my class to use this table. I've cr...