Search Results

Search found 139 results on 6 pages for 'dbml'.

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

  • Circular reference error when outputting LINQ to SQL entities with relationships as JSON in an ASP.N

    - by roosteronacid
    Here's a design-view screenshot of my dbml-file. The relationships are auto-generated by foreign keys on the tables. When I try to serialize a query-result into JSON I get a circular reference error..: public ActionResult Index() { return Json(new DataContext().Ingredients.Select(i => i)); } But if I create my own collection of "bare" Ingredient objects, everything works fine..: public ActionResult Index() { return Json(new Entities.Ingredient[] { new Entities.Ingredient(), new Entities.Ingredient(), new Entities.Ingredient() }); } ... Also; serialization works fine if I remove the relationships on my tables. How can I serialize objects with relationships, without having to turn to a 3rd-party library? I am perfectly fine with just serializing the "top-level" objects of a given collection.. That is; without the relationships being serialized as well.

    Read the article

  • How to handle encrypted column in SQL Server Database in LINQ to SQL?

    - by Raja
    Hi Guys, We are in the process of encrypting all the SSN columns (had to do it now due to security audit). We already built the DBML and now we have to change it. Can you guys let me know if there is a good way of handling this in LINQ to SQL? We use stored procedures for Insert, Update and Delete but use LINQ to SQL for all our selects (ease of use). Do I have to change the format for those tables with SSN or Is there any other manner we can handle it in LINQ to SQL? Thanks, Raja

    Read the article

  • SQL Server CE, Visual Studio 2008/2010 RC, and Linq-to-Sql

    - by blu
    I added an .sdf to my project, added a table, added a Linq-to-Sql dmbl, and tried to add the table to the dbml. The result was an error: "The selected object(s) are an unsupported data provider" This happens in both VS 2008 Professional SP1 and 2010 RC Ultimate. I found someone talking about using SQL Metal to generate the file, but I didn't enjoy that 2 years ago, and after a little playing around I recall why. Does anyone know if this is going to be supported in the release version? Should I abandon SQL Server CE and just use SQLite (with DbLinq)? Thanks for any insight.

    Read the article

  • Is there a suggested solution structure for ASP.NET MVC Production Apps

    - by Eoin Campbell
    In general, I don't like to keep code (BaseClasses or DataAccess Code) in the App_Code directory of an ASP.NET Site. I'll usually pull this stuff out into a MySite.BusinessLogic & MySite.DataAccess DLL's respectively. I'm wondering should I be doing the same for ASP.NET MVC. Would it be better to Organise the solution something along the lines of MySite.Common - DLL - (Basic Functionality built on .NET System Dlls) MySite.DAL - DLL - (DataAccessLayer & DBML Files) MySite.Models - DLL - (MVC Models e.g. Repository Classes) MySite.Controllers - DLL (MVC Controllers which use Models) MySite - ASP.NET MVC Site. Or am I missing something... presumably, I'll lose some of the nice (Add View, Go To Controller, context menu items that have been added)

    Read the article

  • exception with Linq to SQL using sdf file

    - by Ben
    Hi, I've set up a project with an SDF local database file and am trying to access it using an LINQ To SQL (".dbml") file. I have used the connection string provided by the sdf file and can instanciate the object with out a problem: thisDataContext = new MyDataContext(GetConnectionString()); However, whenever i try to access any information from it eg var collection = (from MyObject p in thisDataContext.MyTable select p); I get the error - "The table name is not valid. [ Token line number (if known) = 2,Token line offset (if known) = 14,Table name = Person ]" I am using Visual Studio 2008 SP1 .Net 3.5 and SQL 2008 CE. I gather something similar happened for SQL 2005 CE and a Hotfix was released, but i would have thought the fix would have been fixed in this version before release. Does anyone know the fix for this? Thanks

    Read the article

  • Creating a new record using AJAX in ASP.NET-MVC

    - by RememberME
    I am having the hardest time wrapping my head around this. I recently asked this question Create/Edit/Save data in a jQuery pop-up for ASP.NET-MVC and Linq2Sql I'm sure that the response is the right way to go, but I just can't figure out how to write the back-end code to make it work. I originally made my site by following the nerddinner tutorial. I have a subcontracts model and a subcontracts controller. On my subcontract entry page, I'd like for there to be a pop-up/dialog box where the user can enter a new company if the company isn't already in the drop-down list. Do I need to create a new company controller? I wouldn't have a company model b/c the company table is linked to my subcontracts table within the subcontracts dbml. Can anyone point me to an example somewhere? Or offer any help.

    Read the article

  • Linq2SQL using Update StoredProcedure

    - by PeterTheNiceGuy
    We use queries generated by Linq for data retrieval but for INSERT and UPDATE we do not allow generated SQL, but restrict to the use of stored procedures. I connected the Update and the Insert behaviour in the DBML to the stored procedures. The procedures are called, the data gets inserted/updated = all if fine, except in the case of optimistic concurrency. If a record was changed between retrieval and update, the update should fail. When Linq generates the Update statement itself, it throws a ChangeConflictException as expected, but using the stored procedure no Exception is thrown. Thanks a lot for any help on this!

    Read the article

  • LinqDataSource wizard table list is not refreshing after updating LinqToSql classes

    - by dotnet_learner
    I have changed my dbml file like this. I have deleted all the tables and stored procs. I added new tables and stored procs from a new database. In the code-behind, I can access the new tables and stored procs. However, in the LinqDataSource using the same dbContext when I'm trying to configure the LinqDataSource. I can see all the old tables in the wizard drop-down. How to refresh the the wizard drop-down so that I can select the newly added tables? Deleting the old LinqDataSourceand adding a new one is not working.

    Read the article

  • Linq sql Attach, Update Check set to Never, but still Concurrency conflicts

    - by remdao
    In the dbml designer I've set Update Check to Never on all properties. But i still get an exception when doing Attach: "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported." This approach seems to have worked for others on here, but there must be something I've missed. using(TheDataContext dc = new TheDataContext()) { test = dc.Members.FirstOrDefault(m => m.fltId == 1); } test.Name = "test2"; using(TheDataContext dc = new TheDataContext()) { dc.Members.Attach(test, true); dc.SubmitChanges(); }

    Read the article

  • Will this safely delete my record?

    - by Sergio Tapia
    I hate these three tables that. Two tables have a many to many relationship and as such it generates a third table. I'm using Linq-to-SQL and in the .dbml file I've dragged all the folder there to the graphic surface. Here is the method I'm using to delete an Area safely. Remember that documents are associated to an Area, so I can't just delete it and leave documents hanging. ScansDataContext db = new ScansDataContext(); /// <summary> /// Deletes an Area object from the database along with all associations in the database. /// </summary> /// <param name="area">Area object to save</param> public void Delete(Area area) { db.DocumentAreaRelations.DeleteAllOnSubmit(area.DocumentAreaRelations); db.Areas.DeleteOnSubmit(area); db.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict); }

    Read the article

  • Can't Add LINQ to SQL classes to projects in VS2010

    - by MisterJames
    I just ran into something in Visual Studio 2010 RC that wasn't previously happening (like, yesterday). No software changes here, but I did run into some muck yesterday when compiling that required a reboot. I am unable to add LINQ to SQL classes to any project through the add dialog. I have created ASP.NET web sites, ASP.NET MVC projects - both of these as 'templated' and as 'empty' - and there appear to be no templates installed or available. I have made sure that the project targets the 4.0 Framework. I can easily add a new database and the ADO.NET entity framework templates are there. As a workaround I can copy a DBML file to my project, delete all tables and sprocs, update the connection string and use the leftover shell (the designer works fine like this), but it's a pain. Has anyone else had their templates drop? Figured out how to reinstall them?

    Read the article

  • troubles with generated constructor in linq2sql

    - by zerkms
    After adding one more table to linq2sql .dbml schema i got Value cannot be null. Parameter name: mapping Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: mapping and it refers to autogenerated file: Line 45: #endregion Line 46: Line 47: public db() : Line 48: base(global::data.Properties.Settings.Default.nanocrmConnectionString, mappingSource) Line 49: { Any ideas why this hapenned and how to solve this?

    Read the article

  • Is testability alone justification for dependency injection?

    - by fearofawhackplanet
    The advantages of DI, as far as I am aware, are: Reduced Dependencies More Reusable Code More Testable Code More Readable Code Say I have a repository, OrderRepository, which acts as a repository for an Order object generated through a Linq to Sql dbml. I can't make my orders repository generic as it performs mapping between the Linq Order entity and my own Order POCO domain class. Since the OrderRepository by necessity is dependent on a specific Linq to Sql DataContext, parameter passing of the DataContext can't really be said to make the code reuseable or reduce dependencies in any meaningful way. It also makes the code harder to read, as to instantiate the repository I now need to write new OrdersRepository(new MyLinqDataContext()) which additionally is contrary to the main purpose of the repository, that being to abstract/hide the existence of the DataContext from consuming code. So in general I think this would be a pretty horrible design, but it would give the benefit of facilitating unit testing. Is this enough justification? Or is there a third way? I'd be very interested in hearing opinions.

    Read the article

  • GetRolesForUser tries to get Roles on old username?

    - by Xaisoft
    I have a section on a page where a user can change their username. This is basically the code for that: user.UserName = txtNewUserName.Text; user.Save(); user is a class in my dbml and Save calls SubmitChanges on the data context. The name is changed in the database, so when it calls the following method, it fails because it is trying to get the user with the old username instead of the one that is in the database now. public override string[] GetRolesForUser(string username) { return dc.Users.Where(u => u.UserName== username) .SingleOrDefault().Roles .Select(r => r.RoleName).ToArray<string>(); }

    Read the article

  • Is it safe to convert varchar and char into nvarchar and nchar in SQL Server?

    - by Svish
    We currently have a number of columns in the database which are of type varchar. The application that uses them are in C# and it uses Linq2Sql for the communication (or what to call it). We would like to support unicode characters, which means we would have to convert the varchar columns into nvarchar. Is this a safe operation? Is it just a matter of changing the column type and updating the dbml file, or are there more stuff that needs to be done? Any changes in the C# code? Do I need to somehow convert the text that already exist in the database manually, or is it handled for me?

    Read the article

  • LINQ to SQL stored procedures with multiple results in Visual Studio 2008

    - by Jeremy
    I'm using visual studio 2008 and I've created a stored procedure that selects back two different result sets. I drag the stored proc on to a linq to sql dbml datacontext class, causing visual studio to create the following code in the cs file: [Function(Name="dbo.List_MultiSelect")] public ISingleResult<DataAccessLayer.DataEntities.List_MultiSelectResult> List_MultiSelect() { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))); return ((ISingleResult<DataAccessLayer.DataEntities.List_MultiSelectResult>)(result.ReturnValue)); } Shouldn't the designer generate the code to use IMultipleResults? Or do I have to hand code that?

    Read the article

  • Linq issue retrieving single value from mssql

    - by Anicho
    Hey Guys, having an issue with linq, I am basically doing the following but it is saying it is "UserProfile does not contain definition for Username" in the current context where I wrote "u.Username" but it does exist I have added UserProfile table to MyDbml.dbml and if I connect to another table it works fine. TiamoDataContext context = new TiamoDataContext(); var user = (from u in context.UserProfiles where u.Username == UsernameLabel select u).FirstOrDefault(); I am flustered by what small detail I have missed out to get this to work, anyone have any clues it would be much appreciation.

    Read the article

  • "Cleanly" Deploying an ASP.NET Application with LINQ to SQL Server

    - by Bob Kaufman
    In my development environment, my SQL Server is PHILIP\SQLEXPRESS. In testing, it's ANNIE, and the live environment will have a third name yet to be determined. I would have assumed that updating the following statement in web.config would have been enough: <add name="MyConnectionString"providerName="System.Data.SqlClient" connectionString="Data Source=PHILIP\SQLEXPRESS;Initial Catalog=MyDtabase;Integrated Security=True" /> When using SqlConnection, SqlCommand, SqlDataReader and friends, that's all it took. Using LINQ, it doesn't seem to work that nicely. I see the servername repeated in my .dbml file as well as in Settings.settings. After changing it in all of those places, I get it to work. However if I'm doing a few deployments per day during testing, I want to avoid this regimen. My question is: is there a programmatic solution for LINQ to SQL that will allow me to specify the connection string once, preferably in web.config, and get everybody else to refer to it?

    Read the article

  • Why Could Linq to Sql Submit Changes Fail for Updates Despite Data in Change Set

    - by KevDog
    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 ([State] = @p4) AND ([ZipCode] = @p5) AND ([CoordinateID] = @p6) AND ([CoordinateSourceID] IS NULL) AND ([CreatedDate] = @p7) AND ([Country] = @p8) AND (NOT ([IsDeleted] = 1)) AND (NOT ([IsNonSACOGZip] = 1))',N'@p0 uniqueidentifier,@p1 varchar(15),@p2 varchar(8000),@p3 varchar(10),@p4 varchar(2),@p5 varchar(5),@p6 uniqueidentifier,@p7 datetime,@p8 varchar(2)',@p0='92550F32-D921-4B71-9622-6F1EC6123FB1',@p1='125 Main Street',@p2='',@p3='Sacramento',@p4='CA',@p5='95864',@p6='725E7939-AEE3-4EF9-A033-7507579B69DF',@p7='2010-06-15 14:07:51.0100000',@p8='US' Sure enough, no set statement. I also called context.GetChangeSet() and the proper values are in the updates section. Also, I checked the .dbml file and all of the properties Update Check values are 'Always'. I am completely baffled on this one, any help out there?

    Read the article

  • LINQ - Linq to Sql - Specified cast is not valid - Please Help!

    - by thiag0
    I am trying to do the following... Request request = ( from r in db.Requests where r.Status == "Processing" && r.Locked == false select r).SingleOrDefault(); It is throwing the following exception... Message: Specified cast is not valid. StackTrace: at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) at GDRequestProcessor.Worker.GetNextRequest() The .DBML file schema matches my database table that I am trying to select from so I have no clue why I am having this problem. Can anyone help me? Thanks in advance!

    Read the article

  • InvalidOperationException sequence contains more than one element even when only one element

    - by user310256
    I have three tables, tblCompany table, tblParts table and a link table between them tblLinkCompanyParts. Since tblLinkCompanyParts is a link table so the columns that it has are LinkCompanyPartID(primary key), CompanyID from tblCompany table and PartID from tblParts as foreign keys. I have tied them up in the dbml file. In code if I write LinkCompanyParts.Parts (where LinkCompanyParts is an object of the tblLinkCompanyParts type) to get to the corresponding Part object I get the "InvalidOperationException: Sequence constains more than one element". I have looked at the data in the database and there is only one Parts record associated with the LinkCompanyPartID. The stack trace reads like at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at System.Data.Linq.EntityRef`1.get_Entity() at ... I read about SingleOrDefault vs FirstOrDefault but since the link table should have a one-one mapping therefore I think SingleOrDefault should work and besides "SingleOrDefault" statement is being generated behind the scenes in the designer.cs file at the following line return this._Part.Entity; Any ideas?

    Read the article

  • VS 2010 Entity Repository Error Class member EntityBase.id is unmapped.

    - by Steve
    In my project I have it set up so that all the tables in the DB has the property "id" and then I have the entity objects inherit from the EntityBase class using a repository pattern. I then set the inheritance modifier for "id" property in the dbml file o/r designer to "overrides" Public MustInherit Class EntityBase MustOverride Property id() As Integer End Class Public MustInherit Class RepositoryBase(Of T As EntityBase) Protected _Db As New DataClasses1DataContext Public Function GetById(ByVal Id As Integer) As T Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault End Function End Class Partial Public Class Entity1 Inherits EntityBase End Class Public Class TestRepository Inherits RepositoryBase(Of Entity1) End Class the line Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault however produces the error "Class member EntityBase.id is unmapped" when i use VS 2010 using the 4.0 framework but I never received that error with the old one. Any help would be greatly appreciated. Thanks in advance.

    Read the article

  • VS 2010 Entity Repository Error

    - by Steve
    In my project I have it set up so that all the tables in the DB has the property "id" and then I have the entity objects inherit from the EntityBase class using a repository pattern. I then set the inheritance modifier for "id" property in the dbml file o/r designer to "overrides" Public MustInherit Class EntityBase MustOverride Property id() As Integer End Class Public MustInherit Class RepositoryBase(Of T As EntityBase) Protected _Db As New DataClasses1DataContext Public Function GetById(ByVal Id As Integer) As T Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault End Function End Class Partial Public Class Entity1 Inherits EntityBase End Class Public Class TestRepository Inherits RepositoryBase(Of Entity1) End Class the line Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault however produces the error "Class member EntityBase.id is unmapped" when i use VS 2010 using the 4.0 framework but I never received that error with the old one. Any help would be greatly appreciated. Thanks in advance.

    Read the article

  • Losing scope for DataContex using LINQToSQL intermediately

    - by greektreat
    I am having a weird Situation with my DataConext. All My code is in C# I have a DLL project for my data access layer and business Layer which and Winforms project for my UI layer. My Data access Layer's Namespace is xxx.Data this is where have my xxx.dbml I also have xxx.Data.BusinessObjects name space of course for my business object in that project In my UI Layer I have these namespaces xxxApp(for Forms), xxxApp.Controls (For Controls) I have lost scope of the DataContext, it was accessible now when I do a Rebuild Solution I sometimes get compile errors saying for example: Error 34 'xxx.Data.xxxDataContext' does not contain a definition for 'SubmitChanges' and no extension method 'SubmitChanges' accepting a first argument of type 'xxx.Data.xxxDataContext' could be found (are you missing a using directive or an assembly reference?) Also intelisense doesn't recognize the methods and table classes from my xxxDataContext anymore I can access all object fine when I am in the DLL project but now in the Winforms project this is very strange. If anyone can help me out I would be extremely grateful!

    Read the article

  • How can I bind an Enum to a DbType of bit or int?

    - by uriDium
    Hi I am using Linq2Sql and want to bind an objects field (which is enum) to either a bit or a int type in the database. For example I want have a gender field in my model. I have already edited the DBML and changed the Type to point to my enum. I want to create Radio buttons (which I think I have figured out) for gender and dropdown lists for other areas using the same idea. My enum looks like this public enum Gender { Male, Female } Mapping between DbType 'int' and Type 'Project.Models.Gender' in Column 'Gender' of Type 'Candidate' is not supported. Any ideas on how to do this mapping. Am I missing something on the enums.

    Read the article

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