linq-to-sql

Repository pattern - Switch out the database and switch in XML files

Repository pattern - Switch out the database and switch in XML files. Hello I have an asp.net MVC 2.0 project and I have followed the Repository pattern. Periodically, I am losing access to the database server so I want to have another mechanism in place (XML files) to continue developing. It is not possible to have a local version of...

Generate non-identity primary key

My workplace doesn't use identity columns or GUIDs for primary keys. Instead, we retrieve "next IDs" from a table as needed, and increment the value for each insert. Unfortunatly for me, LINQ-TO-SQL appears to be optimized around using identity columns. So I need to query and update the "NextId" table whenever I perform an insert. Fo...

Using Linq-To-SQL I'm getting some weird behavior doing text searches with the .Contains method. Looking for Help or Thoughts on what I am doing wrong.

I have a table, where I need to do a case insensitive search on a text field. If I run this query in LinqPad directly on my database, it works as expected Table.Where(tbl => tbl.Title.Contains("StringWithAnyCase")) // also, adding in the same constraints I'm using in my repository works in LinqPad // Table.Where(tbl => tbl.Title.Contai...

Can I use the same DBML to access different tables?

I have many tables with identical schemas but different names. Can I create a single representative DBML/DataContext and re-use it for all the tables, or do I have to drag every table into the dbml designer? ...

association of more than one model to a listview

I have 3 Tables in my database. Each table has 3 fields each, excluding the ID field. out of which 2 fields are of type nvarchar. None of the tables are related. My ListView in the application helps the user to search my database, the search being incremental. The search includes the nvarchar fields of the 3 tables ie, 6 fields in total...

Converting SQL to LINQ to XML

I'm writing the following code to convert SQL to LINQ and then to XML: SqlConnection thisConnection = new SqlConnection(@"Data Source=3BDALLAH-PC;Initial Catalog=XMLC;Integrated Security=True;Pooling=False;"); thisConnection.Open(); XElement eventsGive = new XElement("data", from c in ?????? select new XElement("ev...

Crystal report using Linq-to-sql

Hello, I am bit confusing in generating crystal report from linq-to-sql object in my WpfApplication. crystalreport1 rpt = new crystalreport1(); datacontextclass1 db = new datacontextclass1(); var q = (from records in db.emp select records).toList(); rpt.setDataSource(q); crystalviewer.reportsource(rpt); I have done above steps... b...

Building an application that includes a DB, and need recommendations

I'm going to build a little system for personal use, and I want it to save data to a database. The language is going to be C#, and so I'd like to use this opportunity to get my head around LINQ to SQL. I have some DB experience and I know my SQL, but it was all in school using Access, which is giving me trouble, and so I'd like to use an...

Linq-to-SQL statement issue

I am basically looking to bind a search query to a gridview which is nice, but this must be done by a users input query (sort of like a search function). I can get single values and rows returned, but how would I get it to search all columns in my database for the inputted values and return it? My code so far is: Void SearchFunction() ...

LINQ to SQL does not update when data has changed in database

I have this problem where after a field (say Field3 in table MyTable) is updated on the database, MyTable.Field3 (in C#) is still returning the old value. I suspect there is some caching...? How do I force it to: Read the value from the database? OR Update the value in the MyTable class? Or is there anything I miss? I am new to LINQ ...

Linq filtering an IQueryable<T> (System.Data.Linq.DataQuery) object by a List<T> (System.Collection.Generic.List) object?

My IQueryable line is: // find all timesheets for this period - from db so System.Data.Linq.DataQuery var timesheets = _timesheetRepository.FindByPeriod(dte1, dte2); My List line is: // get my team from AD - from active directory so System.Collection.Generic.List var adUsers = _adUserRepository.GetMyTeam(User.Identity.Name); I ...

Serialization mode in LINQ to SQL

what is means of serailzation mode in LINQ to SQL? what architecture does LINQ to SQL uses internally (connected or disconnected architecture)? ...

Can I stop the dbml designer from adding a connection string to the dbml file?

We have a custom function AppSettings.GetConnectionString() which is always called to determine the connection string that should be used. How this function works is unimportant to the discussion. It suffices to say that it returns a connection string and I have to use it. I want my LINQ to SQL DataContext to use this so I removed all...

Change LINQ2SQL property in partial class?

Hi, I have a table in my LINQ2SQL diagram with a column called DayOfWeek in table JourneyBooking. The designer.cs has the definition of this as: [Column(Storage="_DayOfWeek", DbType="TinyInt NOT NULL")] public int DayOfWeek { get { return this._DayOfWeek; } set { if ((this._DayOfWeek != value)) ...

LINQ to SQL get grouped MIN with JOIN

I'm having trouble with a LINQ to SQL query getting the min value using Visual Basic. Here's the SQL: SELECT RC.AssetID, MIN(RC.RecCode) AS RecCode, JA.EngineerNote from JobAssetRecCode RC JOIN JobAssets JA ON JA.AssetID = RC.AssetID AND JA.JobID = RC.JobID WHERE RC.InspState = 2 AND RC.RecCode > 0 AND RC.JobID = @JobID GROUP BY RC.Asse...

Linq-to-sql Add item and a one-to-many record at once

I have a function where I can add articles and users can comment on them. This is done with a one to many relationship like= "commentId=>ArticleId". However when I try to add the comment to the database at the same time as I add the one to many record, the commentId is not known. Like this code: Comment comment = new Comment(); comment....

How to have a where clause on an insert or an update in Linq to Sql?

I am trying to convert the following stored proc to a LinqToSql call (this is a simplified version of the SQL): INSERT INTO [MyTable] ([Name], [Value]) SELECT @name, @value WHERE NOT EXISTS(SELECT [Value] FROM [MyTable] WHERE [Value] = @value) The DB does not have a constraint on the field that is getting checked for so in ...

Does Linq to SQL or Linq to Entities 4.0 support the hierarchyid datatype

Is their a way to use linq to SQL/Entities 4.0 to work with the hierarchy datatype? ...

System.InvalidOperationException: Cannot attach an entity that already exists.

I'm attempting to attach to an object that I've previously detached from. My detach operation is as follows: partial class Organization : IDetachable { #region IDetachable Members public void Detach() { if (IsAttached) { PropertyChanged = null; PropertyChanging = null; //...

Possible to use Tables of same type in Linq to SQL?

Lets say I've got an object model, where I have many collections of the same type. For example something like class StockMarketData { List<SummaryData> WeeklySummary; List<SummaryData> MonthlySummary; } class SummaryData { DateTime DateTime {get; set;} double Value {get; set;} } Those lists will map onto database tables. I...