Sql Server - Rolling Back Entity Framework Transaction, Cached Item Persist?

Aug 23, 2011

I'm using an Entity Framework context, and sometimes would like to create a transaction so that the client can do multiple changes and then commit/rollback them all together.However, if many changes were made, and SaveChanges() was called multiple times, after which a rollback is called, entities that were commited already, will remain the way they were commited, and would not roll back.Here's how my transaction-relative functions look like:

Public Sub BeginTransaction()
Dim context = HttpContext.Current.GetObjectContext()
If Not context.Connection.State = ConnectionState.Open Then
context.Connection.Open()
End If

[Code]...

Not only does the test fail, but it also leave the ObjectContext in an unstable mode, because it still has invalid changes in it.

View 1 Replies


ADVERTISEMENT

Rolling Back A Transaction With MySQL Connector?

Mar 23, 2011

I have one multi-row INSERT statement (300 or so sets of values) that I would like to commit to the MySQL database in an all-or-nothing fashion. insert into table VALUES

(1, 2, 3),
(4, 5, 6),
(7, 8, 9);

In some cases, a set of values in the command will not meet the criteria of the table (duplicate key, for example). When that happens I do not want any of the previous sets added to the database. I've implemented this with the following code, however, my rollback command doesn't appear to be making a difference. I've used this documentation: http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqltransaction.html

Dim transaction As MySqlTransaction = sqlConnection.BeginTransaction()
sqlCommand = New MySqlCommand(insertStr, sqlConnection, transaction)
Try

[code]....

I get the DUPLICATE KEY exception thrown, no Rollback Exception thrown, and every set of values up to duplicate key committed to the database.

View 1 Replies

If DDL Statement Fails Whole Transaction Is Rolled Back Sql Server?

Mar 24, 2009

I have a series of DML and DDL(Drop View only) statements that I need to execute under single transaction from VB.net app. I m using commandObj, and kept above all I kept beginTransaction statement. Everything is working fine expect when error is returned by Drop statement. If Drop statement returns error then whole transaction is rolledback. I do not want tthis. I want to continue even if Drop fails keeping the other DML statements that were executed before Drop.

View 5 Replies

Sql Server - Derived Associations In .Net Entity Framework?

Aug 9, 2010

I want to have a single table that represents a person and have a number of other tables (such as Student/Teacher) use the Person table to store information related to a person. Unfortunately the entity framework doesn't seem to like it when I try to add an association between the Student or Teacher class and I don't understand why. The Person table contains a column called ParentEntityID, which equals either a StudentEntityID or a TeacherEntityID. In an ideal world I would like to be able to reference the Person table by going Student.Person.FirstName instead of Student.Entity.Person1.FirstName. The error .Net returns when trying to connect the Student/Teacher table to the Person table is:

Error 3007: Problem in Mapping Fragments starting at lines 265, 289: Non-Primary-Key column(s) [ParentEntityID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.

The actual database I am working with is a bit more complicated and has a number of tables connected to the Entity table, which makes my object model pretty ambiguous and was hoping to be able to clean it up a bit by using the entity framework.I am using VB.Net 3.5 in a web application.

Update...In an attempt to internalize the different types of relationships I can form, I have been playing with this simple example and have come up with the following possibilities:And the reason why I cannot make an association between the Student and Address table is because that relationship is not enforced in the database. If I wanted an association between these two tables I would need to re-think the design of my database. Is that correct?

View 1 Replies

C# - Implementing Transaction Processing To Persist Application Data

May 27, 2011

Let's say an application needs to persist mostly immutable data. Let's say the application's data files can grow fairly large. How would you implement a simple transaction processing so that changes are either successfully committed or rolled back?

The only requirement is to use built-in .Net libraries. (no databases, no third party libraries)

Here's my current solution. The data file will have three main sections: (1) header, (2) data, (3) index. For now, the header section simply contains an offset to the start of the index section. The data section will store mostly immutable data. The index section will contain serialized objects with enough information to access the data section.

When the application starts, it only needs to deserialize objects from index section. Anything from the data section can be fetched as needed. As the application gets ready to write changes, it makes a temporary copy of the original header and index sections. These would be small relative to the data section. New data would then be appended to the original data section. Once all data has been written, in memory objects would be serialized to the end of the file to become the new index section.

If all this goes without a hitch, the temporary file can be deleted. If something goes wrong, the temporary file can be used to restore the data file to its original state.

Will this work or is there a more elegant approach?

View 1 Replies

Excessive SQL Server Processes For Entity Framework Based Application

Jun 27, 2011

We are currently developing a WPF/Entity-Framework based application.One of our requirements was to allow the user option to select which environment(testing, training, or production) they will connect to when logging in.Each connection option points to its own database.In order to do this we are creating new EF contexts in the following way:[code]We have made sure that all new contexts are being disposed of once its job is completed.The problem is this: when the users are using the application we are seeing hundreds of SQL Server processes in SQL Server's activity monitor. Some individual users have upwards of 30+ processes associated when using the app. Once the user shuts down the app the associated processes all disappear - but while the app is running these processes seem to stick around.

View 1 Replies

C# - Are Microsoft Entity Framework And ADO.NET Entity Framework (.edmx) The Same

May 13, 2010

c# - Are Microsoft Entity Framework and ADO.NET Entity Framework (.edmx) the same?

View 7 Replies

VB OracleTransaction Not Rolling Back

Sep 14, 2010

I'm calling a third party stored procedure in Oracle from VB that is not rolling back.

Code first (I'm simplifying):

Connection string:
String sqlstr = "SERVER=x.x.x.x;Database=db;uid=sa;pwd=admin;Connect Timeout=60; Min Pool Size=5; Max Pool Size=100;";

The call (I've just forced a rollback immediately after the execute to test it):

Dim Oraclecon As New OracleConnection(_OracleConnection)
Dim sqlCon As New SqlConnection(_SQLConnection)
Dim oTrans As OracleTransaction = Nothing

[Code.....

I can't give the details of the stored procedure but it does a commit and rollback inside it.

Either way, it is doing an insert, and that immediate rollback does not rollback the insert.

View 2 Replies

.net - ADO.net Entity Framework - Update Only Certain Properties On A Detached Entity

Jul 22, 2009

I want to update an entity without loading the entity from the database first. I've accomplished this but only by knowing all of the entities properties and then using the "attachto" method. My issues is i don't want my app to need to remember all of the properties. Example:

[Code]....

View 3 Replies

.NET Sample Entity Framework 4.2 Code First Entity Splitting?

Dec 14, 2011

Entity Splitting: one class, two or more tables.Here is how it is done in C#, but I need to get it working in vb.net.One more thing: the class name and table columns do not match, so I have to be able to map that out, too.I have to get this to work this way because the place I'm working at right now is a vb.net only shop and the database schema is fubar, but they have so much (millions) of lines of code done directly against the database in both asp classic, vb.net, AND asp.net webforms that changing the schema right now is not realistically possible.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.Map(m =>

[code]....

View 1 Replies

Setup Is Not Rolling Back If Condition If False

Jun 11, 2011

if one installer class in my project and in custom action doing some procedure to validate the serial key using user interface editor during setup creation. while installing the set up if the condition is not true the setup in rolling back it is installing.

[Code]...

View 1 Replies

Asp.net - Using ExecuteQuery() With Entity Framework, Entity Class

Jan 16, 2011

I am trying to jump from ASP Classic to asp.net. I have followed tutorials to get Entity Framework and LINQ to connect to my test database, but I am having difficulties figuring out ExecuteQuery(). I believe the problem is that I need an "entity class" for my database, but I can't figure out how to do it. Here is my simple code:

Dim db as New TestModel.TestEntity
Dim results AS IEnumerable(OF ???) = db.ExecuteQuery(Of ???)("Select * from Table1")

From the microsoft example site, they use an entity class called Customers, but I don't understand what that means.

View 1 Replies

C# - Inherited Entity Item Not Recognized As Entity?

Feb 11, 2011

I am trying to create a generic typed class, but am running into a problem. Here is my basic class definition:

public class QueueObject<T> where T : System.ServiceModel.DomainServices.Client.Entity
{
public string LoadingMessage { get; set; }
public System.ServiceModel.DomainServices.Client.EntityQuery<T> Query { get; set; }
}

I am trying to add instances of this class to a queue

private Queue<QueueObject<Entity>> _queue;
this._queue.Enqueue(new QueueObject<MyEntity> {Query = MyContext.GetMyEntitiesQuery(), LoadingMessage = "Loading some stuff"});

This doesn't work. I get an error saying that QueueObject cannont be converted to QueueObject. I don't understand because MyEntity inherits from Entity.

Public Class QueueObject(Of T As System.ServiceModel.DomainServices.Client.Entity)
Public Property LoadingMessage As String
Public Property Query As System.ServiceModel.DomainServices.Client.EntityQuery(Of T)
End Class

[code]....

View 2 Replies

Entity Framework - C# Or .Net?

Feb 18, 2010

My company is tossing around the idea of using the Entity Framework when it comes out with .NET 4. We are currently a VB.NET shop, but have some interest in switching to C#.Is there any major arguments for or against such a move?Does EF with C# hold any advantages in performance, coding ease, etc over VB.NET?

View 10 Replies

Keeping Tables Cached On Server In Project

Mar 7, 2010

I have an ASP.NET project which is a front-end to a database. In addition to the large tables, the DB contains a few small tables to help normalize the larger tables with common values. I have a VB.NET project which loads the smaller tables into memory, using "Shared" (i.e., "static" in C#) member variables, and uses them. I have a call to load the tables in Global.asax - Application_Start. This works for a while. That is, Application_Start runs when I first run my project, loads the cached values, and will correctly keep them in memory for a while.

What I'm seeing (when running my project via Visual Studio 2008 Debugger, hosted locally) is:

A) The Application_Start code will run more than once. Not in a row, but after the user has navigated to some other pages, I'll see (my breakpoint in) another call to initialize the cache, coming form Application_Start. Is it expected?

B) The "Shared" variable that was set to True when the cache was initialized is now False again (which should only happen when the class is first loaded). Similarly, all the data that was chached is no longer present. That is, it looks like VB is unloading all the Shared members. Is this expected?

View 1 Replies

Add A Many-To-Many Relation In Entity Framework?

Apr 17, 2009

I am a newbie. I have been able to Add new entities where there is a One-To-Many Relation. I am having a problem (don't Know how to do it) adding a new Entity when the relation is using Many-To-Many. In my EDM I have:

[Code]....

View 1 Replies

ADO.NET Entity Framework Tools?

Apr 16, 2011

I downloaded the VB 2010 Express software, the total files that we included in the download was 15, but it only loaded up 12 of these files. The following downloads did not get loaded as follows:MS Visual Studio 2010 ADO.NET Entity Framework Tools

MS HelpViewe 1.0 x64

I tried reinstalling the downloads that did not using the VB Express 2010 setup, but they do no appear on the list of downloads, only the SP1 for MS SQL Server 2008 Express Server (x64).Do I require the downloads that did not load.

View 2 Replies

Asp.net Mvc - Entity Framework With Database?

Apr 21, 2012

Here are the entities that i have...

Public Class Account
Public Property AccountId As integer
Public Property AccountDescription As String
Public Property Transactions As List(Of Transaction)
End Class

[Code]...

i would like to make it suc that when i do "db.Account.find(1)" for example it also loads in the list of all transactions which have the coresponding AccountId. I'm not too sure what type of relationship this is?? anyway, right now i can do

Dim acct As Account = db.Account.Find(1) acct.Transactions = from ts in db.transactions select ts where ts.AccountId = acct.accountid but i know this is not the correct way, there must be a way to map this out so that entity can just load everything in one shot right?

View 1 Replies

Entity Data Framework 101

Sep 28, 2011

I am used to using datasets for my projects in terms of data access. I now set myself an easy app to work on in order to learn the entity data framework and how to retrieve & manipulate data.Can anyone guide me through on where to start, what are the advantages of this model, In what scenarios should I choose to use entity framework and what are the things (basis) I should now before starting.My datasets are working fine too. Are there any reasons for me not to stick with that way of accessing data? Or is this something to consider depending on the users of the website (for speed purposes etc.)

View 3 Replies

Entity Framework VB Join

Feb 28, 2012

I'm trying to learn EF in visual basic. I'm struggling with finding any easy to understand simple tutorial of how to do inner joins.

This is the SQL that i'm trying to replicate in EF:

SELECT Quote.LockedDateTime, IncommingQuoteStatus.StatusDesc, Users.FirstName
+ ' ' + Users.LastName AS UserName
FROM Quote

[Code].....

View 1 Replies

WPF With Entity Framework Or Linq?

Feb 8, 2011

I have some basic expirience in Visual Basic and programming Windows Forms programs. I know now that forms programs are no longer updated by Microsoft and that WPF is the way to go. No to mention the slicker interface you can create. I've also noticed that passing SQL strings to a database is no longer the standard either. It's either Entity Framwork or Linq.

So I am going for a fresh approach. I need to develop a program that will access a sql database and be accessed by about 10 concurrent users within the office. What's the best approach in general? Linq or Entity Framework? Also, could you recommend a book or two for someone who is new to WPF and Entity Framework? I do have some programming expirience, just none with WPF or the new ways of ADO.net 4.

View 4 Replies

Oracle Transaction - Rollback Your Transaction If You Haven't Commit The Transaction

Oct 31, 2011

I want to know that do you still need to rollback your transaction if you haven't commit the transaction that was created earlier.

[Code]...

View 3 Replies

.net - Entity Framework 4 Save And Cancel?

Nov 3, 2010

I'm currently testing the entity framework 4 for a simple app I wish to build.

how do you save and cancel changes on a record basis? Using the save changes method on the context persists all the changes to the database.

View 3 Replies

.net - Entity Framework Query With More Than One Join VB?

May 10, 2012

I'm trying to use the Entity Framework to create a complex query and get stuck in the joins. After browsing some of the documentations, I cannot seem to find the correct solution, so maybe someone here can help.

I have a data structure where a family has several family members, each of which can have more than one entry in the income table (on different registration dates) and can have more than one entry in the healthconditions table.

[Code]...

View 1 Replies

.Net Entity Framework - Let Keyword With A Condition

Jul 7, 2011

I need to make a if-else statement in the query meaning I only want to add the OpenAmount to ExpectedAmount if the type = Cash, the problem is that it only gives me the cash row not the other row.

[Code]...

View 1 Replies

Active Record With Entity Framework?

May 14, 2012

I'm working on a project that was built using ADO.NET (raw sql) and Active Record pattern. I am slowly moving it away from ADO.NET to Entity Framework Code First 4.3.Here is an example of the pattern. The interface is a static Load and an instance Save (and Delete -- not shown).

Public Class Part
Public Property Id as Integer
Public Shared Function Load(_id As Integer) As Part

[code].....

View 1 Replies

Asp.net - Accomplish With Entity Framework Without Using Two Contexts?

Apr 6, 2011

I have the following code:

Private Sub btnReserve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReserve.Click
Using dbContext As pbu_housingEntities = New pbu_housingEntities

[Code].....

executes it always get 0, because the row has not yet been created in the database. I can just move this last bit of code out into its own Context, but is there a better way to do this?

View 2 Replies

Asp.net Mvc - Editable Gridview With Entity Framework

Dec 20, 2011

I am trying to make an MVC index view with bulk editing functionality, but can't seem to get it working. I have replaced the Html.DisplayFor with HTML.editorfor items, and put the whole table in a form which submits back to my index function. I have tried various ideas, but currently my function is

[Code]...

View 1 Replies

Association End Is Not Mapped In ADO Entity Framework?

Jan 15, 2009

I am just starting out with ADO.net Entity Framework I have mapped two tables together and receive the following error:

Error 1 Error 11010: Association End 'OperatorAccess' is not mapped. E:Visual StudioprojectsBrandi IIBrandi IIHospitals.edmx 390 11 Brandi II

View 6 Replies

C# - Column Sequence And The Entity Framework?

Dec 28, 2009

So, when you bind a collection of Entity objects to a grid component, the grid displays those fields in the sequential order they are found in the SQL Table they came from. This shows that the ordinal position of the fields are associated with their corresponding entity properties... somehow or other.

So here is the question: How can I obtain the table field ordinal position by reflecting over an Entity Framework Entity's properties? Let me tell you what I know and what I have tried. Apparently, each data field property in an EF Entity is decorated with a System.Runtime.Serialization.DataMemberAttribute. This attribute appears to have an Order property. However, I have discovered that this property does not contain what I am looking for. The value for all Data Properties in an Entity seems to be -1. What ever order is, it isn't ordinal position.

View 1 Replies







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