Search Results

Search found 213 results on 9 pages for 'submitchanges'.

Page 5/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • How do I do client-side validation in WPF using WCF RIA Services

    - by lsb
    Hi! I've created a WCF RIA Service that I'd like to use with a WPF application. I've added several System.ComponentModel.DataAnnotations validation rules on the entities meta-data, all which work great on the server when I call .SubmitChanges(changeSet) from the client. I'd also like to validate my entities on the client side before I sumbit my changes to the server but I have no idea how to do so. Any help in this regard would be greatly appreciated! Thanks....

    Read the article

  • Generate non-identity primary key

    - by MikeWyatt
    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. For simplicity, I do this immediately creating the new object. Since all operations between creation of the data context and the call to SubmitChanges are part of one transaction, do I need to create a separate data context for retrieving next IDs? Each time I need an ID, I need to query and update a table inside a transaction to prevent multiple apps from grabbing the same value. Is a separate data context the only way, or is there something better I could try?

    Read the article

  • Rollback in lucene

    - by Petrick Lim
    Is there a rollback in lucene? I'm saving & updating database repository & lucene repository simultaneously so that the lucene index & database are in sync.. ex. CustomerRepository.add(customer); SupplierRepository.add(supplier); CustomerLuceneRepository.add(customer); SupplierLuceneRepository.add(supplier); // If this here fails i cannot rollback the customer above DataContext.SubmitChanges();

    Read the article

  • LinqToSql: insert instead of update

    - by Christina Mayers
    I am stuck with this problems for a long time now. Everything I try to do is insert a row in my DB if it's new information - if not update the existing one. I've updated many entities in my life before - but what's wrong with this code is beyond me (probably something pretty basic) I guess I can't see the wood for the trees... private Models.databaseDataContext db = new Models.databaseDataContext(); internal void StoreInformations(IEnumerable<EntityType> iEnumerable) { foreach (EntityType item in iEnumerable) { EntityType type = db.EntityType.Where(t => t.Room == iEnumerable.Room).FirstOrDefault(); if (type == null) { db.EntityType.InsertOnSubmit(item); } else { cur.Date = item.Date; cur.LastUpdate = DateTime.Now(); cur.End = item.End; } } } internal void Save() { db.SubmitChanges(); }

    Read the article

  • Any clever way to fix 'string or binary data would be truncated' warning with LINQ

    - by Simon_Weaver
    Is there a clever way to determine which field is causing 'string or binary data would be truncated' with LINQ. I've always ended up doing it manually by stepping through a debugger, but with a batch using 'SubmitChanges' I have to change my code to inserting a single row to find the culprit in a batch of rows. Am I missing something or in this day and age do I really have to still use a brute force method to find the problem. Please dont give me advice on avoiding this error in future (unless its something much cleverer than 'validate your data'). The source data is coming from a different system where I dont have full control anyway - plus I want to be lazy. PS. Does SQL Server 2008 actually tell me the field name. Please tell me it does! I'll upgrade!

    Read the article

  • An attempt has been made to Attach or Add an entity that is not new Linq to Sql error

    - by Collin Oconnor
    I have a save function for my order entity that looks like this and it breaks on the sumbmitChanges line: public void SaveOrder ( Order order ) { if (order.OrderId == 0) orderTable.InsertOnSubmit(order); else if (orderTable.GetOriginalEntityState(order) == null) { orderTable.Attach(order); orderTable.Context.Refresh(RefreshMode.KeepCurrentValues , order); } orderTable.Context.SubmitChanges(); } The order entity contains two other entities; an Address entity and a credit card entity. Now i want these two entities to be null sometimes. Now my guess for why this is throwing an error is because that both of these entites that are inside order are null. If this is the case, How can I insert an new order into the database with both entities (Address and creditCard) being null.

    Read the article

  • Updating multiple tables with LinqToSql in one unit of work

    - by zsharp
    Table 1: int ID-a(pk) Table 2: int ID-a(pk), int ID-b(pk) Table 3: int ID-b(pk), string C I have the data to insert into Table 1. But I do not have the ID-a, which is autogenerated. I have many string C to insert in Table 3. I am trying to insert row into Table 1, get the ID-a to insert in Table 2 along with the ID-b that is auto-Generated in Table 3 when I submit each string C, all in one submission to db. Right now I am calling dc.SubmitChanges twice in same call. Is it efficient to have to submit changes twice on same DataContext or can this be combined further?

    Read the article

  • keep viewdata on RedirectToAction

    - by Thomas Stock
    [AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateUser([Bind(Exclude = "Id")] User user) { ... db.SubmitChanges(); ViewData["info"] = "The account has been created."; return RedirectToAction("Index", "Admin"); } This doesnt keep the "info" text in the viewdata after the redirectToAction. How would I get around this issue in the most elegant way? My current idea is to put the stuff from the Index controlleraction in a [NonAction] and call that method from both the Index action and in the CreateUser action, but I have a feeling there must be a better way. Thanks.

    Read the article

  • Update specific rows in LINQ to SQL result set.

    - by davemackey
    I have a page with a form on it and needs a range of dates. Thus I've placed a number of textboxes on the page into which users can type dates. When the user clicks the save button I want to trigger a LINQ update to the SQL Server...all the rows already exist, so I'm just updating existing data. How can I do this? For example, lets say my table looks like this: Column Names: Description dateValue Column Values: Birthdate 1/1/1990 Anniversary 1/10/1992 Death 1/1/1993 I want to do something like this: hupdate.Description("Birthdate").dateValue = TextBox1.Text hupdate.Description("Anniversary").dateValue = TextBox2.Text hupdate.Description("Death").dateValue = TextBox3.Text hconfig.SubmitChanges() Is there a way to do this with LINQ?

    Read the article

  • .Remove(object) on a List<T> returned from LINQ to SQL compiled query won't delete the Object right

    - by soldieraman
    I am returning two lists from the database using LINQ to SQL compiled query. While looping the first list I remove duplicates from the second list as I dont want to process already existing objects again. eg. //oldCustomers is a List returned by my Compiled Linq to SQL Statmenet that I have added a .ToList() at the end to //Same goes for newCustomers for (Customer oC in oldCustomers) { //Do some processing newCustomers.Remove(newCusomters.Find(nC=> nC.CustomerID == oC.CusomterID)); } for (Cusomter nC in newCustomers) { //Do some processing } DataContext.SubmitChanges() I expect this to only save the changes that have been made to the customers in my processing and not Remove or Delete any of my customers from the database. Correct? I have tried it and it works fine - but I am trying to know if there is any rare case it might actually get removed

    Read the article

  • retrivenewly inserted record ID with Linq2SQL

    - by devmania
    hi, i am using the following private BlogDataContext db = new BlogDataContext (); article.Created = DateTime.UtcNow; article.Modified = DateTime.UtcNow; db.Articles.InsertOnSubmit(article); db.SubmitChanges( ); int id = article.Id; i am wondering is this save, i mean will it give me the Id of the article user inserted or will there be case of concurrences if another user update the article in fraction of second of second after this user ? thanks in advanced.

    Read the article

  • Inserting data using Linq

    - by Ani
    I have a linq query to insert data in table. but its not working. I saw some example on internet tried to do like that but doesn't seems to work. Tablename: login has 3 columns userid, username and password. I set userid as autoincrementing in database. So I have to insert only username and password everytime.Here's my code. linq_testDataContext db = new linq_testDataContext(); login insert = new login(); insert.username = userNameString; insert.Password = pwdString; db.logins.Attach(insert);// tried to use Add but my intellisence is not showing me Add.I saw attach but dosent seems to work. db.SubmitChanges();

    Read the article

  • Duplicate LINQ to SQL entity / record?

    - by GONeale
    Hi guys, What would be considered the best practice in duplicating [cloning] a LINQ to SQL entity resulting in a new record in the database? The context is that I wish to make a duplicate function for records in a grid of an admin. website and after trying a few things and the obvious, read data, alter ID=0, change name, submitChanges(), and hitting an exception, lol. I thought I might stop and ask an expert. I wish to start with first reading the record, altering the name by prefixing with "Copy Of " and then saving as a new record.

    Read the article

  • Handling auto-incrementing IDENTITY SQL Server fields with LINQ to SQL in C#

    - by Maxim Z.
    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 relationship). At what point is the IDENTITY column value generated and how can I obtain it from my code? Is the right approach to: Create the object that has the IDENTITY column Do an InsertOnSubmit() and SubmitChanges() to submit the object to the database table Get the value of the ID property of the object

    Read the article

  • My Linq to Sql Insert code seems to work fine but I don't get a record in the database

    - by Alex
    Here is my code. In the debugger, I can see that the code is running. No errors are thrown. But, when I go back to the table, no row has been inserted. What am I missing?? protected void submitButton_Click(object sender, EventArgs e) { CfdDataClassesDataContext db = new CfdDataClassesDataContext(); string sOfficeSought = officesSoughtDropDownList.SelectedValue; int iOfficeSought; Int32.TryParse(sOfficeSought, out iOfficeSought); Account act = new Account() { FirstName = firstNameTextBox.Text, MiddleName = middleNamelTextBox.Text, LastName = lastNameTextBox.Text, Suffix = suffixTextBox.Text, CampaignName = campaignNameTextBox.Text, Address1 = address1TextBox.Text, Address2 = address2TextBox.Text, TownCity = townCityTextBox.Text, State = stateTextBox.Text, ZipCode = zipTextBox.Text, Phone = phoneTextBox.Text, Fax = faxTextBox.Text, PartyAffiliation = partyAfilliatinoTextBox.Text, EmailAddress = emailTextBox.Text, BankName = bankNameTextBox.Text, BankMailingAddress = bankAddressTextBox.Text, BankTownCity = bankTownCityTextBox.Text, BankState = bankStateTextBox.Text, BankZip = bankZipTextBox.Text, TreasurerFirstName = treasurerFirstNameTextBox.Text, TreasurerMiddleName = treasurerMiddleNamelTextBox.Text, TreasurerLastName = treasurerLastNameTextBox.Text, TreasurerMailingAddress = treasurerMailingAddressTextBox.Text, TreasurerTownCity = treasurerTownCityTextBox.Text, TreasurerState = treasurerStateTextBox.Text, TreasurerZipCode = treasurerZipTextBox.Text, TreasurerPhone = treasurerPhoneTextBox.Text //OfficeSought = iOfficeSought }; act.Suffix = suffixTextBox.Text; db.SubmitChanges(); }

    Read the article

  • NullReferenceException makes me want to shoot myself

    - by rockinthesixstring
    Ok, so once upon a time, my code worked. Since then I did some refactoring (basic stuff so I thought) but now I'm getting a null reference exception, and I can't bloody well figure out why. Here's where it starts. note, this is the logout method, but all of my ActivityLogs sections are throwing this error Function LogOut(ByVal go As String) As ActionResult ActivityLogService.AddActivity(AuthenticationHelper.RetrieveAuthUser.ID, _ IActivityLogService.LogType.UserLogout, _ HttpContext.Request.UserHostAddress) ActivityLogService.SubmitChanges() ''# more stuff happens after this End Function The service is pretty straight forward (notice the ERROR THROWN HERE) Public Sub AddActivity(ByVal userid As Integer, ByVal activity As Integer, ByVal ip As String) Implements IActivityLogService.AddActivity Dim _activity As ActivityLog = New ActivityLog With {.Activity = activity, .UserID = userid, .UserIP = ip.IPAddressToNumber, .ActivityDate = DateTime.UtcNow} ActivityLogRepository.Create(_activity) ''#ERROR THROWN HERE End Sub And the Interface that the Service uses looks like this Public Interface IActivityLogService Sub AddActivity(ByVal userid As Integer, ByVal activity As Integer, ByVal ip As String) Function GetUsersLastActivity(ByVal UserID As Integer) As ActivityLog Sub SubmitChanges() ''' <summary> ''' The type of activity done by the user ''' </summary> ''' <remarks>Each int refers to an activity. ''' There can be no duplicates or modifications ''' after this application goes live</remarks> Enum LogType As Integer ''' <summary> ''' A new session started ''' </summary> SessionStarted = 1 ''' <summary> ''' A new user is Added/Created ''' </summary> UserAdded = 2 ''' <summary> ''' User has updated their profile ''' </summary> UserUpdated = 3 ''' <summary> ''' User has logged into they system ''' </summary> UserLogin = 4 ''' <summary> ''' User has logged out of the system ''' </summary> UserLogout = 5 ''' <summary> ''' A new event has been added ''' </summary> EventAdded = 6 ''' <summary> ''' An event has been updated ''' </summary> EventUpdated = 7 ''' <summary> ''' An event has been deleted ''' </summary> EventDeleted = 8 ''' <summary> ''' An event has received a Up/Down vote ''' </summary> EventVoted = 9 ''' <summary> ''' An event has been closed ''' </summary> EventCloseVoted = 10 ''' <summary> ''' A comment has been added to an event ''' </summary> CommentAdded = 11 ''' <summary> ''' A comment has been updated ''' </summary> CommentUpdated = 12 ''' <summary> ''' A comment has been deleted ''' </summary> CommentDeleted = 13 ''' <summary> ''' An event or comment has been reported as spam ''' </summary> SpamReported = 14 End Enum End Interface And the repository is equally straight forward Public Sub Create(ByVal activity As ActivityLog) Implements IActivityLogRepository.Create dc.ActivityLogs.InsertOnSubmit(activity) End Sub The stack trace is as follows [NullReferenceException: Object reference not set to an instance of an object.] MyApp.Core.Domain.ActivityLogService.AddActivity(Int32 userid, Int32 activity, String ip) in E:\Projects\MyApp\MyApp.Core\Domain\Services\ActivityLogService.vb:49 MyApp.Core.Controllers.UsersController.Authenticate(String go) in E:\Projects\MyApp\MyApp.Core\Controllers\UsersController.vb:258 lambda_method(Closure , ControllerBase , Object[] ) +163 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +409 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +52 System.Web.Mvc.<c_DisplayClass15.b_12() +127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +436 System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +305 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830 System.Web.Mvc.Controller.ExecuteCore() +136 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +232 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44 System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult ) +42 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 System.Web.Mvc.<c_DisplayClasse.b_d() +61 System.Web.Mvc.SecurityUtil.b_0(Action f) +31 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +56 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +110 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +690 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +194 here's an image of the error when attached to the debugger. And here's an image of the DB schema in question Can anyone shed some light on what I might be missing here?

    Read the article

  • What is '=>'? (C# Grammar Question)

    - by Daniel
    I was watching a Silverlight tutorial video, and I came across an unfamiliar expression in the example code. what is = ? what is its name? could you please provide me a link? I couldn't search for it because they are special characters. code: var ctx = new EventManagerDomainContext(); ctx.Events.Add(newEvent); ctx.SubmitChanges((op) => { if (!op.HasError) { NavigateToEditEvent(newEvent.EventID); } }, null);

    Read the article

  • How to retrieve indentity column vaule after insert using LINQ

    - by Hobey
    Could any of you please show me how to complete the following tasks? // Prepare object to be saved // Note that MasterTable has MasterTableId as a Primary Key and it is an indentity column MasterTable masterTable = new MasterTable(); masterTable.Column1 = "Column 1 Value"; masterTable.Column2 = 111; // Instantiate DataContext DataContext myDataContext = new DataContext("<<ConnectionStrin>>"); // Save the record myDataContext.MasterTables.InsertOnSubmit(masterTable); myDataContext.SubmitChanges(); // ?QUESTION? // Now I need to retrieve the value of MasterTableId for the record just inserted above. Kind Regards

    Read the article

  • Updating an object with L2S with ASP.NET MVC

    - by Paul
    Is there an easier way to update an object with L2S other then doing it property by property? This is what I am doing now: Public ActionResult Edit(Object obj) { var objToUpdate = _repository.Single<Object>(o => o.id = obj.id); objToUpdate.Prop1 = obj.Prob1; objToUpdate.Prop2 = obj.Prop2; ... _repository.SubmitChanges(); } I am hoping there is a way to just say objToUpdate = obj then submit the changes??? Any help on this would be appreciated!

    Read the article

  • ASP.NET MVC - How do I implement validation when using Data Repositories? (Visual Basic)

    - by rockinthesixstring
    I've built a UserRepository interface to communicate with my LINQ to SQL Data layer, but I'm trying to figure out how to implement validation. Here is what my AddUser subroutine looks like Public Sub AddUser(ByVal about As String, ByVal birthdate As DateTime, ByVal openid As String, ByVal regionid As Integer, ByVal website As String) Implements IUserRepository.AddUser Dim user = New User user.About = about user.BirthDate = birthdate user.LastSeen = DateTime.Now user.MemberSince = DateTime.Now user.OpenID = openid user.RegionID = regionid user.UserName = String.Empty user.WebSite = website dc.Users.InsertOnSubmit(user) dc.SubmitChanges() End Sub And then my controller will simply call AddUser(...) But I haven't the foggiest idea on how to implement both client side and server side validation on this. (I think I would prefer to use jQuery AJAX and do all of the validation on the server, but I'm totally open to opinions)

    Read the article

  • LINQ saving images to varbinary

    - by m4rc
    I'm having issues saving images to a varbinary(Max) field using LINQ. I can save files in the region of 10KB to the database no problems, but when it comes to files bigger than that, it's as though it doesn't even try. I've had a look in the SQL Server Profiler and when the file is around 10KB I can see the full insert statement in the detail pane. However, when the file is a bit bigger, the detail pane doesn't show anything, although any data besides the varbinary field is written to the database. The data is in the Data Object just before SubmitChanges so I can't figure out what's happening between now and then!

    Read the article

  • How to return a message from my repository class to my controller and then to my view in asp.net-mvc

    - by Pandiya Chendur
    I use this for checking an existing emailId in my table and inserting it...It works fine how to show message to user when he tries to register with an existing mailId.... if (!taxidb.Registrations.Where(u => u.EmailId == reg.EmailId).Any()) { taxidb.Registrations.InsertOnSubmit(reg); taxidb.SubmitChanges(); } and my controller has this, RegistrationBO reg = new RegistrationBO(); reg.UserName = collection["UserName"]; reg.OrgName = collection["OrgName"]; reg.Address = collection["Address"]; reg.EmailId = collection["EmailId"]; reg.Password = collection["Password"]; reg.CreatedDate = System.DateTime.Now; reg.IsDeleted = Convert.ToByte(0); regrep.registerUser(reg); Any sugesstion how to show "EmailID" already exists to the user with asp.net mvc...

    Read the article

  • Copy Rows in a One to Many with LINQ (2 SQL)

    - by Refracted Paladin
    I have a table that stores a bunch of diagnosis for a single plan. When the users create a new plan I need to copy over all existing diagnosis's as well. I had thought to try the below but this is obviously not correct. I am guessing that I will need to loop through my oldDiagnosis part, but how? Thanks! My Attempt so far... public static void CopyPlanDiagnosis(int newPlanID, int oldPlanID) { using (var context = McpDataContext.Create()) { var oldDiagnosis = from planDiagnosi in context.tblPlanDiagnosis where planDiagnosi.PlanID == oldPlanID select planDiagnosi; var newDiagnosis = new tblPlanDiagnosi { PlanID = newPlanID, DiagnosisCueID = oldDiagnosis.DiagnosisCueID, DiagnosisOther = oldDiagnosis.DiagnosisOther, AdditionalInfo = oldDiagnosis.AdditionalInfo, rowguid = Guid.NewGuid() }; context.tblPlanDiagnosis.InsertOnSubmit(newDiagnosis); context.SubmitChanges(); } }

    Read the article

  • Update through Linq-to-SQL DataContext not working.

    - by Puneet Dudeja
    I have created a small test for updating table using Linq-to-SQL DataContext as follows: using (pessimistic_exampleDataContext db = new pessimistic_exampleDataContext()) { var query = db.test1s.First(t => t.a == 3); if (query.b == "a") query.b = "b"; else query.b = "a"; db.SubmitChanges(); } But after executing this code in a console application in Main method, when I select records from the table, the record is not updated. I have debugged through the code, and it is not even throwing any exception. What can be the problem ?

    Read the article

  • Copy Rows in a One to Many with LINQ to SQL

    - by Refracted Paladin
    I have a table that stores a bunch of diagnosis for a single plan. When the users create a new plan I need to copy over all existing diagnosis's as well. I had thought to try the below but this is obviously not correct. I am guessing that I will need to loop through my oldDiagnosis part, but how? Thanks! My Attempt so far... public static void CopyPlanDiagnosis(int newPlanID, int oldPlanID) { using (var context = McpDataContext.Create()) { var oldDiagnosis = from planDiagnosi in context.tblPlanDiagnosis where planDiagnosi.PlanID == oldPlanID select planDiagnosi; var newDiagnosis = new tblPlanDiagnosi { PlanID = newPlanID, DiagnosisCueID = oldDiagnosis.DiagnosisCueID, DiagnosisOther = oldDiagnosis.DiagnosisOther, AdditionalInfo = oldDiagnosis.AdditionalInfo, rowguid = Guid.NewGuid() }; context.tblPlanDiagnosis.InsertOnSubmit(newDiagnosis); context.SubmitChanges(); } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >