C# - Linq To Sql - Executing Multiple Queries On The Same Transaction?

Nov 2, 2010

I am creating entries in a contract table using linq to sql.

One column needs to conditionally be assigned an application number from a range of values.

I'd like to simply increment the max existing value, however it is a multi-user application and I'm concerned about multiple contracts receiving the same app number if they happen too close together.

Is there a way to either force the entire thing to use the same transaction, or to execute both during the same submit?

View 4 Replies


Similar Messages:

DataSource Controls :: LINQ To SQL - Multiple Queries Doesn't Return Any Results

May 25, 2010

I am working on asp.net 3.5 and in MVC using Linq to SQL classes. In my MVC project i am calling stored procedure using linq to sql that conatin query joining two tables.Below is my code in Partial class

[
Function(Name="dbo.GetUserWiseThreadDetail_SP")]
[ResultType(typeof(Thread))]
[ResultType(typeof(Reply))]
public
IMultipleResults GetUserWiseThreadDetail_SP([Parameter(DbType="VarChar(30)")]
string userID)
{
ExecuteResult result = this.ExecuteMethodCall(this,
(MethodInfo)(MethodInfo.GetCurrentMethod())), userID);
return ((IMultipleResults)(result.ReturnValue));
}

In one of the controller i have made one more class

public class
MypostIndexData
{
public
IEnumerable<Thread> Thrds {
get;
set; }
public
IEnumerable<Reply> Repls {
get;
set; }
public MypostIndexData(IEnumerable<Thread>
thrds,IEnumerable<Reply> repls)
{
this.Thrds=thrds;this.Repls=repls;
}
}

finally coding of controller action method

ForumDataContext pmforum = new
PMForumDataContext();
public
ActionResult MyPosts(string userId)
{
IEnumerable<Thread>thrds;
IEnumerable<Reply>repls;
IMultipleResults result = pmforum.GetUserWiseThreadDetail_SP(userId); (this satement doesnot give any result,if i execute stored proc in
sql it give the results)
thrds = result.GetResult<Thread>();
List<Thread> thrdlist =
new
List<Thread>(thrds);
repls = result.GetResult<Reply>();
List<Reply> replylist;
if (repls !=
null)
{
replylist = new
List<Reply>(repls);
}
return View(new
MypostIndexData(thrds,repls));

I am unable to understand why i am not getting any results?

View 5 Replies

ADO.NET :: Linq To Sql Many To Many Insert Into Database In One Transaction

Mar 27, 2011

i have a Tag Table TagId TagName

Post Table PostId PostName

TagPost Table TagId PostId

How can i do a many to many insert into database in one transaction?

View 4 Replies

MVC :: Linq - Use Normal Sql Queries?

Jan 11, 2011

When i see MVC Music store. They have used ADO.NET entity data model and used LINQ language to perform operation in DB.. Is there any way to use normal sql queries?

View 3 Replies

ADO.NET :: Converting SQL Queries To Linq?

Jul 31, 2010

How to convert SQL Queries to Linq.is their any tool available to convert SQL Queries to Linq

View 2 Replies

C# - Difference Between These LINQ Queries?

Mar 18, 2010

I use LINQ-SQL as my DAL, I then have a project called DB which acts as my BLL. Various applications then access the BLL to read / write data from the SQL Database.

I have these methods in my BLL for one particular table:

public IEnumerable<SystemSalesTaxList> Get_SystemSalesTaxList()
{
return from s in db.SystemSalesTaxLists
select s;
}
public SystemSalesTaxList Get_SystemSalesTaxList(string strSalesTaxID)
{
return Get_SystemSalesTaxList().Where(s => s.SalesTaxID == strSalesTaxID).FirstOrDefault();

[Code].....

View 2 Replies

ADO.NET :: Combine 2 Linq Queries?

Jul 27, 2010

Is it possible to combine these 2 linq queries ?

[Code]....

View 2 Replies

ADO.NET :: How To Build Dynamic Linq To SQL Queries

Nov 7, 2010

I'm trying to do something that on the face of it is very simple.

If I have 5 text boxes, and 1 of them is blank, I want to exclude that textbox from the query, rather than searching for where a field is blank.

I've tried to do a bit of research into dynamic linq queries, but have come up empty handed, or what I've found doesn't seem to quite answer my question.

View 3 Replies

ADO.NET :: Time Difference In Linq Queries?

Aug 20, 2010

I have my Linq query in which i need to find time difference(not days difference).

The field in database is datetime.

Dim ldtToday
As DateTime = TimeOfDay
Dim SR_RM_InnerJoin =
From SR
In lcntxRT60Entities.RtSReports _
Join RM
In lcntxRT60Entities.RtRMaster
On SR.RtRMaster.ReportID
Equals RM.ReportID _
Select SR, RM _
Where SR.TID = 1 _
And --(Check) SR.ReportDeliveryTime.Value.AddDays(1) < ldtToday

How can i check if the time field of the record is less than current time??

View 5 Replies

C# - Efficient And Proper Linq Queries From Database

Nov 9, 2010

A sample linq query from MSDN: var expensiveInStockProducts = from p in products where p.UnitsInStock > 0 && p.UnitPrice > 3.00M select p; Does this query select EVERY column from the database table immediately, or does it return some sort of pointer that retieves the actual column data on demand? ie. If there are 50 columns in my table and I only use a single p.UnitsInStock in my actual code, then am I retrieving 50 times more data than I expected?

View 2 Replies

ADO.NET :: How To Improve The Application Performance While Writing LINQ Queries

Dec 17, 2010

how to improve the application performance while writing LINQ Queries ?Like the optimization techniques.

View 2 Replies

Linq To SQL - How To Get Total Number Of Results When Paging Without Two Queries

Dec 29, 2010

I've got the following LINQ query to my IQueryable service

Dim eventcount = EventService.QueryEvents().Count
Dim eventlist = EventService.QueryEvents().Skip((page - 1) * 5).Take(5).ToList

But I'm wondering if there's a way to do this without making two calls to the database?

View 2 Replies

MVC :: Finding Books And Links For Mvc And Learning Linq Queries

Nov 10, 2010

i want to get masterized....in MVC

finding books and links for mvc..and learning linq queries

View 4 Replies

C# - Returning A Max/limit When Using .Include () In LINQ-to-Entities Queries?

Mar 6, 2011

Is there a way to cap the number of records returned when an .Include() method is called on an ObjectQuery<>? Basically, if one of my entities is in a one-to-many relationship, such as a Band entity to a list of Fan entities (where a band can have any number of fans), how can I limit the number of fans returned?

In the example: var band = ctx.Bands.Include("Fans").SingleOrDefault(b => b.BandId == someBandId);

If I use the Include, it will return all fans. How can I query that Fans navigation property to return only a subset or max?

View 2 Replies

ADO.NET :: Preventing Duplicate Records Being Returned From Linq To Sql Queries?

Aug 8, 2010

I've got a linq to sql query that pulls data from 2 different tables and contains an or statement:

[Code]....

The problem I've got is that some queries match both sides of the or statement so it returns the same record twice.

How can I eliminate these duplicates quickly and easily?

View 3 Replies

ADO.NET :: Executing SPROCS As Batch Using Linq?

Aug 17, 2010

I need to add potentially a large number of items to a dataset, this currently works but is quite slow. There are some minor changes I can make to make this fast however the main culprates are the insert statements which are quite complex, With the deletes I changed the structure to be DELETE FROM TABLE WHERE ID IN () Instead of a per ID statement which made quite a difference executing for every 25 rows.The SPROC is linq enabled DbContext.MYSPROC(params) is there a way I could add the Sproc in the context to a batch group that I then execute when the currrent count of insertable items = 25? for each item in insertitems 'Don't want it to execute here

Batch.AddSproc(DbContext.MYSPROC(params))
If Count = 25 THEN Batch.RunSProcs
next

View 2 Replies

ADO.NET :: LINQ Insert Code Not Executing?

Jan 19, 2011

deleted old code

View 3 Replies

Multiple Queries With Multiple CheckBoxes

Jan 25, 2010

I am trying to do multiple queries with multiple CheckBoxes. This code worked until just recently, and I didn't make any changes other than adding a single field to my SQL Server DB; field is named 'Crawl'. Now, nothing works! SearchCheckBox.aspx:

[Code]....

SearchCheckBox.aspx.vb

[Code]....

In DesignView, the error reads 'Error Creating control SqlDataSource3' Literal
content ('connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial
Catalog=PubCrawls;Integrated Security=True" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT ID,
Pub, Street, Neighborhood, City, State, RelativeAddress, Crawl FROM ListofPubs
WHERE (Neighborhood = @Neighborhood1) OR (Neighborhood = @Neighborhood2) OR
(Neighborhood = @Neighborhood3) _
OR (Neighborhood =
@Neighborhood4) OR (Neighborhood = @Neighborhood5) OR (Neighborhood =
@Neighborhood6) OR (Neighborhood = @Neighborhood7) OR (Neighborhood =
@Neighborhood8) OR (Neighborhood = @Neighborhood9) . . .

goes on like this for a while) is not allowed within a 'System.Web.UI.WebControls.SqlDataSource' This line is highlighted red: connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial Catalog=PubCrawls;Integrated Security=True" Finally, there are 19 'Neighborhoods' in my list. There must be a way to loop through the neighborhoods in my SQL statement, right. For Loop or While Loop?

View 3 Replies

DataSource Controls :: Combine The LINQ Queries Together And Have Access To Both Of The Results Independently?

Feb 25, 2010

Is there a way to combine the LINQ queries together and have access to both of the results independently?

[Code]....

View 10 Replies

WCF / ASMX :: Run Multiple Methods Within A Transaction?

Sep 24, 2010

I need to run 5 different WCF methods but within a transaction. Is this possible in WCF? How can I do this in WCf, if it's possible?

The WCF methods will be called from the web service client, which could be an ASP.Net app or Winfoms app.

View 1 Replies

WCF / ASMX :: Multiple Web Methods In One Transaction?

Aug 20, 2010

it may sound a bit newbish question.We have a web service that comunicates with the database and exposes web methods that enables the application to access the database. Each method does only one operation (Insert, Update or Delete). What I need to do is create a transaction that will be consisted of multiple calls to the database, meaning multiple calls of more then one web methods. Can I do that? (I read that if the web method does not throw exception - or ContextUtil.SetAbort() is not called - the transaction will be commited automatically when the web method finishes executing, which I don't want to happen because I want to call another web method in the same transaction, and then manually commit the transaction)

View 2 Replies

SQL Server :: Run Multiple MS Update Queries

Sep 11, 2010

On satisfying the If condition, I need to run 2 MS SQL update queries. How can I accomplish this? I am using C# as the server side language.

View 6 Replies

SQL Server :: SUM In Multiple Queries Of Each Table

Dec 21, 2010

I want to find the sum of each tables fileld. how can do this. i tried the following.but could nt get the correct sum. "SELECT SUM(gb) FROM data20 union all SELECT SUM(gb) FROM data10 union all SELECT SUM(gb) FROM data5 union all SELECT SUM(gb) FROM data6"

View 7 Replies

C# - Using Multiple Sql Queries On Single Button Click

Nov 16, 2010

protected void Button2_Click(object sender, EventArgs e)
{
String a = DropDownList1.SelectedItem.Value;
String b = DropDownList3.SelectedItem.Value.PadLeft(3, '0');
String c = TextBox2.Text.PadLeft(5,'0').ToString();
String d = TextBox3.Text.ToString();
String digit = a+ b + c + d;
try
{
myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testcase;User=root;Password=root;Option=3;");
myConn.Open();
//**
string sql = "select * from testcase.main where reg_no =?";
//**
OdbcCommand cmd = new OdbcCommand(sql, myConn);
//**
cmd.Parameters.AddWithValue("?", digit);
MyReader = cmd.ExecuteReader();
//**
while (MyReader.Read())
{
String f = MyReader["pet_name"].ToString();
String g = MyReader["res_name"].ToString();
Label9.Visible = true;
Label9.Text = f;
Label10.Visible = true;
Label10.Text = "VS";
//Label11.Visible = true;
Label11.Text = g;
}
MyReader.Close();
}
catch (Exception e1)
{
Response.Write(e1.ToString());
}
finally
{
if (MyReader != null && !MyReader.IsClosed)
{
MyReader.Close();
}
if (myConn != null && myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}

I want to add another sql query which is using two tables to fetch the data and than i want to display it in a dropdownlist after fetching data from database. How should i proceed?? Should i create a totally new connection? I tried many different ways like, creating new connection and new reader and entire try and catch block i coded again but on running the website i t was taking very long to load the contents. What i did i modified only this portion(below code) and used the entire try catch again but it dint work.

while (MyReader1.Read())
{
String f = MyReader1["ret"].ToString();
DropDownList1.Items.Add(f);
}

View 2 Replies

Flush Separate Castle ActiveRecord Transaction And Refresh Object In Another Transaction

Jun 15, 2010

I've got all of my ASP.NET requests wrapped in a Session and a Transaction that gets commited only at the very end of the request. At some point during execution of the request, I would like to insert an object and make it visible to other potential threads - i.e. split the insertion into a new transaction, commit that transaction, and move on. The reason is that the request in question hits an API that then chain hits another one of my pages (near-synchronously) to let me know that it processed, and thus double submits a transaction record, because the original request had not yet finished, and thus not committed the transaction record.

So I've tried wrapping the insertion code with a new SessionScope, TransactionScope(TransactionMode.New), combination of both, flushing everything manually, etc. However, when I call Refresh on the object I'm still getting the old object state. Here's some code sample for what I'm seeing:

Post outsidePost = Post.Find(id); // status of this post is Status.Old
using (TransactionScope transaction = new TransactionScope(TransactionMode.New))
{
Post p = Post.Find(id);
p.Status = Status.New; // new status set here
p.Update();
SessionScope.Current.Flush();
transaction.Flush();
transaction.VoteCommit();
}
outsidePost.Refresh();
// refresh doesn't get the new status, status is still Status.Old

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved