Ok the title maybe a little confusing. I have a database with the table Companies wich has one-to-many relotionship with another table Divisions ( so each company can have many divisions ) and division will have many employees.
I have a ListView of the companies. What I wan't is that when I choose a company from the ListView another Lis...
In asp.net(c#),i use linqtosql,In the table,i 've set property of a field Isunique to true.. when the same value inserted again,it shows error(exception) "Cannot insert duplicate key row in object 'dbo.student' with unique index",i need to catch the exception and display the error message.. How to handle sqlexception ? Thanks in advance....
I'm updating a set of objects, but the update fails on a SqlException that says "Incorrect Syntax near 'Where'".
So I crack open SqlProfiler, and here is the generated SQL:
exec sp_executesql N'UPDATE [dbo].[Addresses]
SET
WHERE ([AddressID] = @p0) AND ([StreetAddress] = @p1) AND ([StreetAddress2] = @p2) AND ([City] = @p3) AND ([...
Hello all,
I have this extension method for cloning my LINQ To SQL objects:
public static T CloneObjectGraph<T>(this T obj) where T : class
{
var serializer = new DataContractSerializer(typeof(T), null, int.MaxValue, false, true, null);
using (var ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, obj)...
I have the following code using a normal data context which works great:
var dc = new myDataContext();
Contract.Assume(dc.Cars!= null);
var cars = (from c in dc.Cars
where c.Owner == 'Jim'
select c).ToList();
However when I convert the filter to an extension method like this:
var dc = new myDataContext();
Cont...
Hi, is it possible to access the InfoMessage event handler in a Linq2SQL data context? All of our code uses these messages to display useful information to the end user and since moving to Linq2SQL I cannot figure out how to show these messages. I have checked the connection object of the data context as well as the classes properties wi...
In code, the commented part is what I need to solve... Is there a way to write such query in LINQ? I need this because I will need sorting based on Status.
var result = (
from contact in db.Contacts
join user in db.Users on contact.CreatedByUserID equals user.UserID
join deal in db.Deals on contact.ContactID equals deal.C...
I have a view, AdvertView in my database, this view is a simple join between some tables (advert, customer, properties). Then I have a simple linq query to fetch all adverts for a customer:
public IEnumerable<AdvertView> GetAdvertForCustomerID(int customerID)
{
var advertList =
from advert in _dbContext.AdvertViews
...
I am using linqtosql and inside of linq query, I tried to convert datetime type column to string like 'dd-MM-yy'.
However, I got error as following :
NotSupportedException: Method
'System.String
ToString(System.String)' has no
supported translation to SQL.
following is my linq query :
from ffv in Flo_flowsheet_values
where f...
TransactionScope TransactionABC = new TransactionScope();
try
{
context.Connection.Open();
{
context.ExecuteCommand("insert into test (test) values (1)")
context.SubmitChanges();
context.ExecuteCommand("savepoint test");
context.ExecuteCommand("insert in...
Hi all.
One day I decided to build this nice multi-tier application using L2S and WCF.
The simplified model is : DataBase->L2S->Wrapper(DTO)->Client Application.
The communication between Client and Database is achieved by using Data Transfer Objects which contain entity objects as their properties.
abstract public class BaseObject
...
I am using LINQ to SQL with single table inheritance for an audit log. There is a field/property called Type that i am using as the dicriminator and i have created a base type and a single inherited type (there will be more later if i can actually get this to work).
So that i don't have to write a different method to insert each diffe...
How can i convert this SQL query to its equivalent LINQ 2 SQL statement for VB.NET?
SELECT COUNT(*) AS 'Qty',
IV200.itemnmbr,
IV200.locncode,
IV200.bin,
CAST(IV112.Quantity as int) as 'Qty2' ,
'parentBIN' = isnull(MDS.parentBIN,iv112.bin)
From IV00200 IV200 (nolock)
inner join IV00112 IV112 (nolock)
...
I am trying to find a way so that I can push some common functionality into a base class for my Linq to SQL processing. I have two fields (ID and InsertUpdateOperID) that are common to most but not all of my tables. In my first go around I created a class called BaseEntity that had these fields. Unfortunately all I accomplished was h...
I need to use the appsettings/key for my connection string in a web project, and want to re-use this for my connectionstring in the datacontext designer, but it seems all I can use there is the web.config's connectionStrings, so I have to have my DB location in 2 places in the web.config, how can I force the designer (dbml) to use the ap...
Hi All
I have a C# console application written using Visual Studio 2008.
My system culture is en-GB. I have a Linq query that looks like this:
var myDate = "19-May-2010";
var cus = from x in _dataContext.testTable
where x.CreateDate == Convert.ToDateTime(myDate)
select x;
The resulting SQL query generates and error becaus...
Dear All,
Thanks for your attention in advance,
I’ve met an issue with LINQ-2-SQL designer in VS 2008 SP1 which has made me CRAZY. I use Linq2sql as my DAL. It seems Linq2sql speeds up coding in the first step but lots of issues arise in feature specifically with table or object inheritance.
In this case I have a class Entity that all...
How can i rewrite the below SQL query to its equivalent LINQ 2 SQL expression (both in C# and VB.NET)
SELECT t1.itemnmbr, t1.locncode,t1.bin,t2.Total
FROM IV00200 t1 (NOLOCK)
INNER JOIN
IV00112 t2 (NOLOCK)
ON t1.itemnmbr = t2.itemnmbr
AND t1.bin = t2.bin...
I'm building an ASP.NET MVC site that uses LINQ to SQL to connect to SQL Server, where I have a table that has an IDENTITY bigint primary key column that represents an ID.
In one of my code methods, I need to create an object of that table to get its ID, which I will place into another object based on another table (FK-to-PK relationshi...
I'm trying to create a generic repository for my models. Currently i've 3 different models which have no relationship between them. (Contacts, Notes, Reminders).
class Repository<T> where T:class
{
public IQueryable<T> SearchExact(string keyword)
{
//Is there a way i can make the below line generic
//return db.Co...