I'm trying to create a Linq statement that queries both columns that exist on my entity as properties and those that don't but exist as columns in the database for the entity.
For example, I have a collection of Book entities. Each Book has an ID and Title property and a matching column in the database. But, lets say the table for Book ...
This is my first go at LINQ to SQL. I create my dbml in the designer using a SQL Server Express database. I create a stored procedure called StoredProcedure1, which I also dragged into the dbml. Then I wrote up some code to test if I could update some of the fields. The problem is that no updates occur to the database, but I see the ...
Hello everyone,
I'm really a LINQ newbie. I got an unknown problem:
public static int save(TEntity obj)
{
var table = dbo.GetTable<TEntity>();
var mapping = dbo.Mapping.GetTable(typeof(TEntity));
var pkfield = mapping.RowType.DataMembers.Where(d => d.IsPrimaryKey).Take(1).SingleOrDefault();
if (Conve...
How do i put a nested insert into database using Linq to SQL
my Table is like this:
[Post]
--Post ID
--Post Title
[Attachment]
--Post ID (PFK)
--AttachmentID (PK)
--IMGID (FK)
--VIDID (FK)
[IMG]
--IMGID (PK)
it's a M:N table
basically when i submit a form , it go together with the attachments within the form. Im ok with insert Pos...
I am writing a search form for desktop application and I have a problem with combobox binding.
The user can search for properties by various criteria (city, price, etc).
I want to bind combobox to list of all possible cities, but I want to leave the user the option not to choose anything so it can search properties in all cities.How can ...
I have this LINQ query. The date is stored as a string in the database, but I need to order by it. So I convert it to a DateTime, but it doesn't order.
(from m in dbDataContext.TimeCards
where m.TIMECARDDATE != ""
&& m.TIMECARDDATE != null
orderby Convert.ToDateTime(m.TIMECARDDATE) descending
select Convert.ToDateTi...
While searching for linq conditional where clause, I found this article, the way they use is like below:
var logs = from log in context.Logs
select log;
if (filterBySeverity)
logs = logs.Where(p => p.Severity == severity);
if (filterByUser)
logs = logs.Where(p => p.User == user);
but I was wondering is this method...
I have a LinqToSql query that returns an array of Article objects like so:
return db.Articles.ToArray();
I then loop over this array and start to delete some items that meet a certain criteria, for simplicity let's say I delete them all, like so:
foreach (var item in array)
db.articles.DeleteOnSubmit(item);
The call to Del...
There seems to be lots of examples on implementing Repository pattern for Linq to SQL. Most of them featuring IRepository and DI; Some have implemented Unit of Work and some not. I tried to read as most of the results returned by searches on SO and Google on Linq to SQL repository patterns. Nevertheless I've not come across a complete so...
Hello
Have been able to find similar questions to this but they don't explain exactly the problem I'm having.
I've inherited a database schema that I can't change, and it's slightly ropey, so LINQ doesn't really like it.
We have:
Table A [child table]
OrderId NULL int
Order Table
Id NOT NULL Primary Key Int
There is no foreign-ke...
Given a DataGridView that has a BindingSource set like this:
On a winform, we add a BindingSource object using the designer, called myBindingScource.
Then on the Form.Designer.cs we add this to the InitializeComponents()
myBindingSource.DataSource = typeof(MyLinq.Person); //Mylinq is the autogenerated Linq Model/Diagram
Later, in the...
Is there a way to make the ProjectID check below part of an optional block? I'm a recent .Net convert from JEE and I'm looking for something similar to the Hibernate Criteria API. I'd like to simplify the block below and only have to call Where() once. I'm also not sure of the performance implications of doing a Where() with lambdas as I...
I'm using Linq to SQL on an SQL Compact database. I have a function where I insert multiple records into the database. I only call SubmitChanges at the end of the function. Would using a transaction (using the TransactionScope class) bring me any more performance or advantages?
...
I have a project that was "spiked" using Linq2SQL and is now running into some major query performance issues. Go figure.
Linq actually works pretty well in simple query and command scenarios, but there are a couple filter intense queries that need to be rewritten as Sprocs.
I'm wondering if someone can give me some high level pointer...
My Linq To Sql query
PROJETS = PROJETS.Where(p => (p.VilleArrive != "" && p.VilleArrive != null) && p.VilleArrive.Contains(alerte.VilleArrive));
is translated like this
SELECT * // (many columns)
FROM [dbo].[cov_Projet] AS [t0]
WHERE ([t0].[VilleArrive] <> @p0) // city != ""
AND ([t0].[VilleArrive] IS NOT NULL) // city != nul...
Im using the PredicateBuilder as seen here http://www.albahari.com/nutshell/predicatebuilder.aspx, everything works great, and now i can genrate Dynamic LINQ to SQL expressions, but the thing that i dont understand is why when i am on a loop like this:
var inner = PredicateBuilder.False<MyType>();
foreach (var f in Filtermodel.Instrumen...
Hi folks,
I've got a pretty simple Linq to Sql statement that (on he surface) is working fine. When I check the sql code that it generates, it's trying to retrieve all of the table fields instead of the fields that I just request. Is this normal practice?
here's some psedo code for the linq to sql query :-
var result = (from q in db.F...
Hi,
I am learning LINQ to SQL.I created 2 tables Project and TimeLogs.TimeLog has projectid as foreign key.But, when I drag these 2 tables in designer, the classes generated do not reflect this relationship in the form of entityset.
regards
...
I hope this is easy to spot.
This query has a synatx error;
public static IEnumerable<DailyTimeRecorded> GetPeriodData(
Employee emp, DateTime startDate, DateTime endDate)
{
var listDTR =
from dow in db.DayOfTheWeeks
join dtr in db.DailyTimeRecordeds
on dow....
I have a number of LINQ to SQL tables with the same fields (CreatedDate and CreatedUser).
I would like a usercontrol to display the values from these fields if the data is passed in as an IQueryable<T> or IEnumerable<T>
For example:
public void UpdateStatus<T>(IQueryable<T> data)
{
DateTime? theDate = data.Single().CreatedDate; /...