linq

Automatic properties and Nullable types - are they incompatible?

I have a custom type with a nullable property that I am trying to project into from a nullable column in SQL. I am always getting a 'missingmethodexception' like so: {"Method not found: 'Void MyType.set_Number(System.Nullable`1<Int32>)'."} Is there a problem with trying to project into a custom type with nullable automatic properties?...

LINQ with 3 Tier

Currently I am working on the design of my degree project. Some days ago I began studying LINQ. I found it was interesting and planned to use it in my project but now I am getting confused at some point. When I add the LINQ to SQL class it auto generates entities classes against each table in database. Suppose I have two tables in data...

Timespan to string problem in LINQ query

Hi I have noted that if I use TimespanObj.ToString() the it gives me perfect output like 12:33:00. But I use following linq query. var time = SomeSimpleQuery.Select(t => new { time = t.FromTime.ToString() }); where FromTime is time(7) in SQL Database and Timespan in LINQ-TO-SQL Class (by Default). Then I get the output having forma...

LINQ:: Error in getting User

hi.. i have a table "Users" in database. it have three colu mns Id (bigint) PK Username (varchar) Password (varchar) i want to get user based on id i am u sing this code bt it is giving me error using (var db = new UsersDataContext()) { // ERROR :: Cannot implicitly convert type 'long' to 'bool' ...

Validation and Linq

Hello, I am trying to add validation logic into my application. I have tried to follow this tutorial http://www.a2zdotnet.com/View.aspx?id=75 but I do not have any partial void OnEmailIdChanging(string value) or any "changing" functions. in my class, so I get an error from Visual Studio. It seems that VS did not generate enough code wh...

LINQ ERROR : Explicit construction of entity type

hi.. i am getting this error at GridView1.DataBind(); Explicit construction of entity type 'WebApplication1.MUser' in query is not allowed. using (var db = new UsersDataContext()) { IEnumerable<MUser> user = from u in db.MUsers where u.Id == 1 ...

Multiple Validation Linq

Hello, I am trying to add validation logic into my Linq asp.net application for multiple fields. I have found on the web a lot of tutorial that validate only one element. Is there a good pattern to implement validation and show to the users his multiple mistakes in one time ? Thank you! ...

Bind Exclude Asp.net MVC doesn't work on LINQ Entity

I'm currenty manage to get some time to work on ASP.NET MVC. I'm doing the tutorial Create a Movie Database in ASP.NET MVC, which still uses the ADO.NET Enity Model. I managed to create a List View from the LINQ Entity Model. So here is my problem. The Bind Attribute doesn't work on my SQL Entity. Original Code with Ado.NET pub...

Linq syntax in VB.NET

What I really want is to select these two tables in to an anon type like in Scott Gu's blog: here However, I would settle for this created type "ActiveLots" I am joining two tables together and want to be able to reference columns from each in my result set. I don't seem to be getting the syntax correctly. Dim pi = From p In dc.Inve...

Use LINQ for arbitrary sorting

Let's say we have an entity that has attributes att1 and att2, where att1 can have values a,b,c and att2 can have values 1,2,3. Is it possible to use LINQ so that we can sort items in the collection by applying arbitrary sorting rule without implementing IComparable. I am facing an issue were business requires that on some screens items ...

linq to xml with C# and VS2008

XML Formatted <status> <webresponse> <properties> <props> <imghandle> <image handle=1234> <imagetag>somewhere</imagetag> </image> </imghandle> </props> <props> <imghandle> <image handle=1235> <imagetag>somewhere1</imagetag> </image> </imghandle> </props> </properties> </w...

VB and IGrouping for LINQ query help

I am converting a c# LINQ example: var query = from m in typeof(string).GetMethods() where m.IsStatic == true orderby m.Name group m by m.Name into g orderby g.Count() select new { name = g.Key, overloads = g.Count() }; In the a...

How do I use linq to get the difference of a List<byte[]> and an anonymous type with a byte[] property?

I am new to Linq and extension methods and I guess I just can't grasp the use of all the extension methods yet. I am reading a bunch of files, and after one has been read, I'm storing the hash value of the file into a database (the file names change, and they are moved around). Periodically, I want to check a directory and read any file...

LINQ to MySql Data Provider

Hi, After a quick Google I couldn’t find anything too promising so I was wondering if anyone knew if there is a good/widely used LINQ to MySql Data Provider out there? ...

Split string in Linq select statement

I tried to split a string in a linq query. I got an error says "Unrecognized expression node: ArrayIndex". Does anyone know how to achive this? My code sample is: List<Task> Result= (from t in TaskDB.Tasks select new Task { ...

Using custom attributes

Hello, I am watching a video about [LINQ][1] and came across a problem. In this video, Mike uses some custom attributes for database name and that does not work for me. My code (which works fine): class MyContext : DataContext { public MyContext(string conStr) : base(conStr) { } } class Program { static void Main(stri...

Populating Models using LINQ

I'm trying to figure out a clear way of populating my model classes from LINQ to SQL generated objects. My goal is to keep my Models and LinqModels separate. Say I have the following models: public class Person { public List<Account> Accounts {get; set;} } public class Account { public List<Purchase> Purchases {get; set;} } pub...

Using LINQ to delete child records automatically

I am somewhat new to LINQ and have a quick question regarding deleting. Say, for example I have 2 tables, Orders and OrderItems. Using LINQ, I can easily create a new child record by using order.Items.Add(new OrderItem()); and this will create the child record in the database and update its foreign key to the orderId. This is great...

F# and PLINQ extension methods

While digging deeper into the latest release of F# I tried to have it interacting with PLINQ. I've noticed, however, that the two don't play very nice together code-wise. In fact it didn't seem possible to write code such as the following: open System.Linq let someArray = [|"abc"; "def"|] someArray.AsParallel().Count(new Func<_,_>(fun ...

Linq Select Certain Properties Into Another Object?

So say I have a collection of Bloops Class Bloop Public FirstName Public LastName Public Address Public Number Public OtherStuff End Class Then I have a class of Razzies Class Razzie Public FirstName Public LastName End Class Is it possible using Linq to select the FirstName and LastName out of all the Bloops in the c...