hi there
imagine I have a table like this
Id | Name | City
1 | Tom york | xx
2 | Jim york | xy
3 | tony | new York
4 | Sam york | xz
and I would like to search records with name like '%york%' or city like '%york%'
BUT i want to give more priority to name, so my rresult would be something like:
Id | Name |...
Following linq statement generates multiple trips to the database, is there a way to change this so it does it in one trip?
db.Members.Distinct().Select(
m => new {
Id = m.Id,
PlayTimeSchedules = m.PlayTimeSchedules.Select(pts => pts.DayOfWeek) }
).ToList();
FYI: in this example Distinct is redundant.
There is a...
I have a stored procedure which is returning the scopeidentity. I dropped the table and the stored procedure to the dbml. The return type of the function is
return ((ISingleResult<storedocumentResult>)(result.ReturnValue));
In the C# code I am using the datacontext to insert a new entry into the table via the stored procedure. I need...
Hi guys,
I'm trying to build a query using linq-to-sql and, in order to provide sorting capabilities, I wrote something like this:
private Dictionary<string, Expression<Func<DataAccess.Auditing, object>>> OrderDict { get; set; }
OrderDict = new Dictionary<string,Expression<Func<Augeos.GereonWeb.DataAccess.Auditing, object>>>();
Order...
Scenerio - I am writting a web app that based off of which login box you use (database1 and database2) it will connect you to the cooresponding database. I have set the web.config to hold both connection strings. On the On_Authenticate method of each box I check to authenticate the user and then send a string based on the login box to ...
When I try running...
SELECT * FROM Users WHERE Username = 'ae' it returns matches where the username is æ (ash character).
I was wondering if there's a way to support characters like the ash character but get an exact match for what I'm looking for.
I'd like to search for ae and get just ae, not ae and æ
I'm using SQL Server 2008 an...
Our database has all times stored as UTC, and we know the user's current timezone, so want to return it relative to that. So we want to incorporate the offset in a LINQ projection as so:
var users = from u in this.Context.Users
select new UserWithCorrectedDate
{
Id = u.Id,
FirstNam...
Is this LINQ statment vulnerable to SQL injection?
var result = from b in context.tests
where b.id == inputTextBox.Text
select b;
where context is an Entity and tests is a table.
I'm trying to learn LINQ and I thought that the benefit of it was that it wasn't vulnerable to sql injection, but some stuff I've see has said differ...
I'm using ASP.NET MVC and have a model that has System.Data.Linq.Binary property. The property represents a picture that has been stored in the database as an image column.
I am able to use the picture in my pages by setting up a separate controller action and using Response.OutputStream.Write to dump the Binary object and then setting...
Currently im using EF and using its datacontext directly in all of my actions, but since i started reading about loose coupling and testability im thinking that thats not the best way to go. Im trying to understand all the pro's and con's before i start refactor all my current code.
Problem 1:
Considering that every entity needs its own...
I am using VS2010 with C#, and linq-to-sql.
Does anyone have any ideas of where to start looking for a solution?
My database has a 'Cats' table and there is a 'Feet' and 'EyeColour' table that are both linked to it with a one-to-one relationship. The 'Feet' table works fine with linq-to-sql, but 'EyeColour' does not.
I dragged the Eye...
I am pulling out my hair over here. I have a table that has a UNIQUE Key (IX_tblTable) and the unique key is on a column Number. I am parsing some data from the web and storing it in the table. My latest collection of data from the web contains number THAT ARE NOT CONTAINED IN THE DATABASE. so I am getting data from the site and all ...
Terrible title, I know...
This works and gives me what I'm looking for, but I know there must be a better way to do it:
var query = (from a in DB
where a.Date.HasValue
select a).AsEnumerable();
double avg = (from a in query
select (a.Date.Value.Subtract(a.OtherDate).Days).Average();
Basically,...
I am very new to linq but I have been assigned to add a weighted average by ticks to a pretty complex linq statement.
Goal: get a weighted average from now until the end of specified year for cost types(ingredients,admin...) with rectime(ticks) being the weight
Original Linq Query:
var itemsToAdd =
(from i in dc.I...
Having never used INotifyPropertyChanging i was wondering if anything other than Linq to SQL uses it?
And if Linq to SQL is the only user why does INotifyPropertyChanging exist in System.ComponentModel?
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanging.aspx
...
Hi,
I have something like the following table to search some text:
SearchedTextTable
Id int primary key
Text nvarchar(max)
Code int
The Text is full text indexed, so I made the following table valued function to work with LinqToSQL:
ALTER FUNCTION [dbo].[SearchText] (@keywords nvarchar(4000))
returns @results table (Id int not null)...
Hi.
Is there any software or provider or framework exist that able us to generate DAL layer with Linq To SQL?
thanks.
...
Hello,
In my mvc application I have 2 tables named:
detail(srNo, ID, work), master(ID, name,plan) that are related with foreign key relation ship from detail to master using "ID" field.
"ID" field is primary key of master table.
"srNo" field is primary key of detail table.
From the "ID" field, this 2 tables are joined with foreig...
I have a Parent/Child Table relationship with the ChildTable linking back to the ParentTable via the ParentId foreign key. There's multiple records in the ChildTable for each ParentTable record. For those of use you like rudimentary visuals, here's the diagram.
ParentTable
------------
+Id
Date
ChildTable
------------
+Id
ParentId
Da...
Hi
I am long time user of LINQ2SQL, but have not used the Entity Framework yet.
One thing that is not possible in LINQ2SQL is to use tracked entities in different data contexts, or 'link' objects from different data contexts.
Example:
Foo f = null;
using (var dc = new DB())
f = dc.Foos.Single(x => x.ID = 1);
using (var dc = new...