Search Results

Search found 160 results on 7 pages for 'linq2sql'.

Page 1/7 | 1 2 3 4 5 6 7  | Next Page >

  • How do you use Linq2Sql in your applications ?

    - by this. __curious_geek
    I'm recently migrating to Linq2Sql and all my future projects would be done in Linq2Sql. Having said that, I researched a lot on how to properly plug-in Linq2Sql in application design. what to put at what layer ? Should I use DTOs over Linq2Sql entities ? I did not find any rock-solid material that really talked about one single thing and everyone had their own opinions and I found all of them justified right from their arguments. I'm looking forward to your ideas on how to integrate/use Linq2Sql in projects. My priority is maintenance[it should be maintenable and when multiple people work on same project] and scalabilty [it should have scope of evolution]. Thanks.

    Read the article

  • linq2sql: singleton or using, best practices

    - by zerkms
    what is the preferred practice when linq2sql using (in asp.net mvc applications): to create "singleton" for DataContext like: partial class db { static db _db = new db(global::data.Properties.Settings.Default.nanocrmConnectionString, new AttributeMappingSource()); public static db GetInstance() { return _db; } } or to retrieve new instance when it needed within using: using (db _db = new db()) { ... } the usage of using brings some limitations on code. so I prefer to use singleton one. is it weird practice?

    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

  • Strange exception while using linq2sql

    - by zerkms
    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 Source Error: Line 45: #endregion Line 46: Line 47: public db() : Line 48: base(global::data.Properties.Settings.Default.nanocrmConnectionString, mappingSource) Line 49: { this is what i get if i implement such class: partial class db { static db _db = new db(); public static db GetInstance() { return _db; } } db is a linq2sql datacontext why this hapenned and how to solve this?

    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

  • Linq2Sql Best Practices

    - by this. __curious_geek
    I'm recently migrating to Linq2Sql and all my future projects will be using Linq2Sql. Having said that, I researched a lot on how to properly plug-in Linq2Sql in application design. what to put at what layer ? How do you design your repositories and business layer services ? Should I use DTOs over Linq2Sql entities on interaction layer ? what things should I be careful about ? what problems did you face ? I did not find any rock-solid material that really talked about one single thing and everyone have their own opinions. I'm looking forward to your ideas on how to integrate/use Linq2Sql in projects. My priority is maintenance[it should be maintenable and when multiple people work on same project] and scalabilty [it should have scope of evolution]. Thanks.

    Read the article

  • LINQ2SQL and MS SQL 2000

    - by artvolk
    Good day! I have used LINQ2SQL with MS SQL 2005, but now I need to use it with MS SQL 2000. I have found only article on MSDN that tells about Skip() and Take() oddities on MS SQL 2000 (that's because it lacks ROW_NUMBER(), I suppose) and nothing more. Anyway, does anybody have expirience with LINQ2SQL and MS SQL 2000 combination. P.S. Just wondering: is it possible to model LINQ2SQL class on view, not a real table?

    Read the article

  • Linq2SQL InfoMessage

    - by Paul Oakham
    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 with no luck so I'm wondering if it is possible. Thanks in advance.

    Read the article

  • Business object and linq2SQL

    - by Overdose
    What is the optimal way to write the code which interacts with DB using linq2SQL? I need to add some business logic to the entities. So I guess there are two ways: Write some wrapper class. The main minus is that many fields are the same, so i don't feel it as DRY style. Add business logic methods to linq2sql entities(these classes are partial) directly ???

    Read the article

  • How do I simulate "Is In" using Linq2Sql

    - by flipdoubt
    I often find myself with a list of disconnected Linq2Sql objects or keys that I need to re-select from a Linq2Sql data-context to update or delete in the database. If this were SQL, I would use IS IN in the SQL WHERE clause, but I am stuck with what to do in Linq2Sql. Here is a sample of what I would like to write: public void MarkValidated(IList<int> idsToValidate) { using(_Db.NewSession()) // Instatiates new DataContext { // ThatAreIn <- this is where I am stuck var items = _Db.Items.ThatAreIn(idsToValidate).ToList(); foreach(var item in items) item.Validated = DateTime.Now; _Db.SubmitChanges(); } // Disposes of DataContext } Or: public void DeleteItems(IList<int> idsToDelete) { using(_Db.NewSession()) // Instatiates new DataContext { // ThatAreIn <- this is where I am stuck var items = _Db.Items.ThatAreIn(idsToValidate); _Db.Items.DeleteAllOnSubmit(items); _Db.SubmitChanges(); } // Disposes of DataContext } Can I get this done in one trip to the database? If so, how? Is it possible to send all those ints to the database as a list of parameters and is that more efficient than doing a foreach over the list to select each item one at a time?

    Read the article

  • How do I simulate "In" using Linq2Sql

    - by flipdoubt
    I often find myself with a list of disconnected Linq2Sql objects or keys that I need to re-select from a Linq2Sql data-context to update or delete in the database. If this were SQL, I would use IN in the SQL WHERE clause, but I am stuck with what to do in Linq2Sql. Here is a sample of what I would like to write: public void MarkValidated(IList<int> idsToValidate) { using(_Db.NewSession()) // Instatiates new DataContext { // ThatAreIn <- this is where I am stuck var items = _Db.Items.ThatAreIn(idsToValidate).ToList(); foreach(var item in items) item.Validated = DateTime.Now; _Db.SubmitChanges(); } // Disposes of DataContext } Or: public void DeleteItems(IList<int> idsToDelete) { using(_Db.NewSession()) // Instatiates new DataContext { // ThatAreIn <- this is where I am stuck var items = _Db.Items.ThatAreIn(idsToValidate); _Db.Items.DeleteAllOnSubmit(items); _Db.SubmitChanges(); } // Disposes of DataContext } Can I get this done in one trip to the database? If so, how? Is it possible to send all those ints to the database as a list of parameters and is that more efficient than doing a foreach over the list to select each item one at a time?

    Read the article

  • c# finding matching words in table column using Linq2Sql

    - by David Liddle
    I am trying to use Linq2Sql to return all rows that contain values from a list of strings. The linq2sql class object has a string property that contains words separated by spaces. public class MyObject { public string MyProperty { get; set; } } Example MyProperty values are: MyObject1.MyProperty = "text1 text2 text3 text4" MyObject2.MyProperty = "text2" For example, using a string collection, I pass the below list var list = new List<>() { "text2", "text4" } This would return both items in my example above as they both contain "text2" value. I attempted the following using the below code however, because of my extension method the Linq2Sql cannot be evaluated. public static IQueryable<MyObject> WithProperty(this IQueryable<MyProperty> qry, IList<string> p) { return from t in qry where t.MyProperty.Contains(p, ' ') select t; } I also wrote an extension method public static bool Contains(this string str, IList<string> list, char seperator) { if (String.IsNullOrEmpty(str) || list == null) return false; var splitStr = str.Split(new char[] { seperator }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in splitStr) foreach (string l in list) if (String.Compare(s, l, true) == 0) return true; return false; } Any help or ideas on how I could achieve this?

    Read the article

  • How to perform a Linq2Sql query on the following dataset

    - by Bas
    I have the following tables: Person(Id, FirstName, LastName) { (1, "John", "Doe"), (2, "Peter", "Svendson") (3, "Ola", "Hansen") (4, "Mary", "Pettersen") } Sports(Id, Name) { (1, "Tennis") (2, "Soccer") (3, "Hockey") } SportsPerPerson(Id, PersonId, SportsId) { (1, 1, 1) (2, 1, 3) (3, 2, 2) (4, 2, 3) (5, 3, 2) (6, 4, 1) (7, 4, 2) (8, 4, 3) } Looking at the tables, we can conclude the following facts: John plays Tennis John plays Hockey Peter plays Soccer Peter plays Hockey Ola plays Soccer Mary plays Tennis Mary plays Soccer Mary plays Hockey Now I would like to create a Linq2Sql query which retrieves the following: Get all Persons who play Hockey and Soccer Executing the query should return: Peter and Mary Anyone has any idea's on how to approach this in Linq2Sql?

    Read the article

  • How to move from untyped DataSets to POCO\LINQ2SQL in legacy application

    - by artvolk
    Good day! I've a legacy application where data access layer consists of classes where queries are done using SqlConnection/SqlCommand and results are passed to upper layers wrapped in untyped DataSets/DataTable. Now I'm working on integrating this application into newer one where written in ASP.NET MVC 2 where LINQ2SQL is used for data access. I don't want to rewrite fancy logic of generating complex queries that are passed to SqlConnection/SqlCommand in LINQ2SQL (and don't have permission to do this), but I'd like to have result of these queries as strong-typed objects collection instead of untyped DataSets/DataTable. The basic idea is to wrap old data access code in a nice-looking from ASP.NET MVC "Model". What is the fast\easy way of doing this?

    Read the article

  • Validate Linq2Sql before SubmitChanges()

    - by Nick Gotch
    Can anyone tell me if/how you can validate the changes in a data context in Linq2Sql before calling SubmitChanges(). The situation I have is that I create a context, perform multiple operations and add many inserts alongside other processing tasks and then rollback if the submit fails. What I'd prefer to do is make some kind of "Validate()" call after certain tasks are done so that I can handle it before submitting the entire job.

    Read the article

  • Linq2SQL to produce Like operator

    - by Dante
    Hi, I have a string "Word1 Word2" and I want to transform it to a query such as "Like '%Word1%Word2%'". At the moment I have: from t in Test where t.Field.Contains("Word1 Word2") How to do this in LINQ2SQL? Do I need to create two separate queries for this, can't I write it in the same statement? Thx in advance

    Read the article

  • Applying Domain Model on top of Linq2Sql entities

    - by Thomas
    I am trying to practice the model first approach and I am putting together a domain model. My requirement is pretty simple: UserSession can have multiple ShoppingCartItems. I should start off by saying that I am going to apply the domain model interfaces to Linq2Sql generated entities (using partial classes). My requirement translates into three database tables (UserSession, Product, ShoppingCartItem where ProductId and UserSessionId are foreign keys in the ShoppingCartItem table). Linq2Sql generates these entities for me. I know I shouldn't even be dealing with the database at this point but I think it is important to mention. The aggregate root is UserSession as a ShoppingCartItem can not exist without a UserSession but I am unclear on the rest. What about Product? It is defiently an entity but should it be associated to ShoppingCartItem? Here are a few suggestion (they might all be incorrect implementations): public interface IUserSession { public Guid Id { get; set; } public IList<IShoppingCartItem> ShoppingCartItems{ get; set; } } public interface IShoppingCartItem { public Guid UserSessionId { get; set; } public int ProductId { get; set; } } Another one would be: public interface IUserSession { public Guid Id { get; set; } public IList<IShoppingCartItem> ShoppingCartItems{ get; set; } } public interface IShoppingCartItem { public Guid UserSessionId { get; set; } public IProduct Product { get; set; } } A third one is: public interface IUserSession { public Guid Id { get; set; } public IList<IShoppingCartItemColletion> ShoppingCartItems{ get; set; } } public interface IShoppingCartItemColletion { public IUserSession UserSession { get; set; } public IProduct Product { get; set; } } public interface IProduct { public int ProductId { get; set; } } I have a feeling my mind is too tightly coupled with database models and tables which is making this hard to grasp. Anyone care to decouple?

    Read the article

  • LINQ2SQL: how many datacontexts ?

    - by sh00
    I have a SQL Server 2008 database with 300 tables. The application I have to design is an Windows Forms app, .NET 3.5, C#. Which is the best way to work with LINQ2SQL ? I intend to make a datacontext for each business entity. Is there any problem ? I need to know if this way of working with LINQ has any disadvantage or can create performance issues ? Thanks.

    Read the article

  • Linq2Sql How to write outer join query?

    - by Malcolm
    Hi, I have following SQL tables. ImportantMessages impID Message ImportantMessageUsers imuID imuUserID imuImpID I want to write a Linq2Sql query so that it returns any rows from ImportantMessages that does not have a record in ImportantMessagesUsers. Matchiing fields are impID ----- imuImpID Assume imuUserID of 6

    Read the article

  • Linq2SQL or EntityFramework and databinding

    - by rene marxis
    is there some way to do databinding with linq2SQL or EntityFramework using "typed links" to the bound property? Public Class Form1 Dim db As New MESDBEntities 'datacontext/ObjectContext Dim bs As New BindingSource Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load bs.DataSource = (From m In db.PROB_GROUP Select m) grid.DataSource = bs TextBox1.DataBindings.Add("Text", bs, "PGR_NAME") TextBox1.DataBindings.Add("Text", bs, db.PROB_GROUP) '**<--- Somthing like this** End Sub End Class I'd like to have type checking when compiling and the model changed.

    Read the article

  • Linq2Sql relationships and WCF serialization problem

    - by devmania
    hi, here is my scenario i got Table1 id name Table2 id family fid with one to many relationship set between Table1. id and Table2.fid now here is my WCF service Code [OperationContract] public List<Table1> GetCustomers(string numberToFetch) { using (DataClassesDataContext context = new DataClassesDataContext()) { return context.Table1s.Take(int.Parse(numberToFetch)).ToList( ); } } and my ASPX page Code <body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView"> <div id="CustomerView" class="sys-template" sys:attach="dataview" dataview:autofetch="true" dataview:dataprovider="Service2.svc" dataview:fetchParameters="{{ {numberToFetch: 2} }}" dataview:fetchoperation="GetCustomers"> <ul> <li>{{family}}</li> </ul> </div> though i set serialization mode to Unidirectional in Linq2Sql designer i am not able to get the family value and all what i get is this in firebug {"d":[{"__type":"Table1:#","id":1,"name":"asd"},{"__type":"Table1:#","id":2,"name":"wewe"}]} any help would be totally appreciated

    Read the article

  • How to create custom get and set methods for Linq2SQL object

    - by optician
    I have some objects which have been created automatically by linq2SQL. I would like to write some code which should be run whenever the properties on these objects are read or changed. Can I use typical get { //code } and set {//code } in my partial class file to add this functionality? Currently I get an error about this member already being defined. This all makes sense. Is it correct that I will have to create a method to function as the entry point for this functionality, as I cannot redefine the get and set methods for this property. I was hoping to just update the get and set, as this would mean I wouldn't have to change all the reference points in my app. But I think I may just have to update it everywhere.

    Read the article

1 2 3 4 5 6 7  | Next Page >