Hi All
I have a generic List and i have to find a particular string in the list. Could you please let me know which is the best approach in the below ?
List<string> strlist = new List<string>();
//Add strings to List
if (strlist.Contains("Test"))
{
//string found
}
or
string res = (from d in strlist
...
I've my Model something maybe like this :
public class Person
{
public virtual Guid ID { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
//this LazyList takes IQueryable<T> in constructor
public virtual LazyList<Role> Roles { get; set;...
I have a List, and I would like to compute a double[360] containing the maximum range along each bearing (to the nearest degree). One hitch is that the chart plotting software I'm using requires each degree to be populated with no holes.
I'm aware of the MoreLinq Batch extension, though not quite sure how to use it...
Heres the code I ...
This may be a really elementry question but whats a nice way to include multiple children entities when writing a query that spans THREE levels (or more)?
i.e. I have 4 tables: Company, Employee, Employee_Car and Employee_Country
Company has a 1:m relationship with Employee.
Employee has a 1:m relationship with both Employee_Car and Em...
Ok, I just don't get it.
I've read about as much as I can on the subject without knowing what it's all about:
Why use Expression Trees?
What's a real-world example of when and how I'd use them?
What overall benefit(s) are there in using them?
...
Suppose I have two tables, TableA and TableB. Each record in A has one or more related records in B. Say I want a reusable filter using predicates. I might do something like this (Linq-to-SQL by the way):
private Expression<Func<ARecord, bool>> FilterPredicate()
{
return x => x.Name == "Test";
}
private IQueryable<ARecord> GetRecor...
Linq is great, but it always seems to confuse me a bit.
This is my latest confusion:
Say I have two List<String> objects. We will call them sourceList and destList.
I need a way to find the list of strings that are in sourceList and not in destList AND find the list of strings that are in destList and not in SourceList.
This is a bi...
How do you query a List<string[]> to get the index of the arrays having matches on their sub-arrays and get a return of type System.Collections.Generic.IEnumerable<string[]> ?
EDIT:
I have this:
string[] report = File.ReadAllLines(@".\REPORT.TXT").AsQueryable().Where(s
=> s.StartsWith(".|")).ToArray();
List<string...
What I'm trying to do is take an RSS feel URL and, using LINQ, be able to write a query that will let me sort the subject line of the feed or sort the author line of the feed or even do 'WHERE' clauses that will let me filter by keywords for example.
I know I can read the RSS feed, parse each element, put them into some sort of class ob...
Hey All,
I am using WinForms & C# to access a SQL Server 2008 on my site which's hosted by winhost.com.
I am using the following code to connect to the database, which I figured out for myself:
try
{
SqlConnection scon = new SqlConnection(
"My ConnectionString Info is in here.");
scon.Open();
MessageBox.Show(scon.D...
var emps = from x in DB
where x.ID = 100
select x;
var emp1 = from x1 in DB
where x1.ID = 100
select new { x };
What is difference between these two queries.
If we use anonymous-types is the performance will be increased or any other differences also there?
...
This code is case sensitive, how to make it case insensitive?
public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description)
{
return this.ObjectContext.FACILITY_ITEM.Where(fi => fi.DESCRIPTION.Contains(description));
}
...
Hi,
I have the following question:
It is easy to insert an oBject in database with a form.
Just create an object
link it to the fields in your from.
Post back to controller,
create a new datacontext and do datacontext.InsertOnSubmit(object)
.
public static void AddPage(string lang, Page page)
{
...
When trying to answer this question, I discovered the following:
string s = "test";
var result1 = s.Select(c => (ushort)c); // works fine
var result2 = s.Cast<ushort>(); // throws an invalid cast exception
Why does Cast<T>() fail here? Whats the difference?
...
So I have decided to use XDocument to create a XML file, which was working great until I came across a part where I have to find all the selected items in a ListBox. I am unsure how I should format this.
XDocument xmlDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("...
I have read the various posts regarding this error message and have typically avoided this problem in the past, but still haven't been able to figure this one, why am I getting this error:
System.NotSupportedException: An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContex...
DynamicObject LINQ query with the List compiles fine:
List<string> list = new List<string>();
var query = (from dynamic d in list where d.FirstName == "John" select d);
With our own custom class that we use for the "usual" LINQ compiler reports the error "An expression tree may not contain a dynamic
operation":
DBclass db = new DBcl...
I have three tables from a dataset ds.
var test0 = from a in ds.Tables[0].AsEnumerable()
select a["ID"].ToString();
test0 has the following values --
[0] "8"
[1] "9"
[2] "11"
[3] "2"
[4] "1"
var test1 = from a in ds.Tables[1].AsEnumerable()
select a["SubscriptionID"].ToString();
test1 has ...
I have a linq query
var query = from record in session.Query<Record>()
from brwSet in session.Query<BorrowerSet>()
from brw in session.Query<Borrower>()
where
brw.PrintOrder == 1 && brwSet.PrintOrder == 0
...
Hi Guys,
Come across a problem with the repository pattern combined with the use of abstract classes.
I have a repository which implements a single method returning an ICollection of an abstract type.
Here's my abstract class:
public abstract class Location
{
public abstract string Name { get; set; }
public abstract LocationTyp...