dbml

XRef Relationships in dbml

So I have a database schema like this: Users UserId RoleUserXRef RoleUserId RoleId UserId Roles RoleId Name With foreign keys defined between User & RoleUserXRef and RoleUserXRef & Role. Basically, I have a one to many relationship between users and roles. How would I model this in dbml, such that the generated Use...

Best Practices for Managing Linq to SQL Dbml Files?

I've just started using Linq to SQL, and I'm wondering if anyone has any best practices they can share for managing dbml files. How do you keep them up to date with the database? Do you have a single dbml file for the entire database, or is it split into multiple logical units? How does managing this file work in a team environment? ...

Managing LINQ to SQL .dbml model complexity

This question is addressed to a degree in this question on LINQ to SQL .dbml best practices, but I am not sure how to add to a question. One of our applications uses LINQ to SQL and we have currently have one .dbml file for the entire database which is becoming difficult to manage. We are looking at refactoring it a bit into separate f...

Editing Autogenerated DMBL file for WCF Service

Hi, In our project we have a standard auto-generated designer.cs file, linked to a DBML file, that contains all our object classes that map onto our database tables. We want to pass these objects directly through a WCF Service and so they need decorating with the [DataContract] and [DataMember] attributes where appropriate. What is the...

Autogeneration of a DataContext designer file when using SqlMetal and Visual Studio

I am using SqlMetal to general my DataContext.dbml class for my ASP.net application using LinqToSql. When I initially created the DataContext.dbml file, Visual Studio used this to create a related DataContext.designer.cs file. This designer file contains the DataContext class in C# that is used throughout the app (and is derived from the...

Linq to SQL Class - Stored Procedure Signature Change

I have a Linq to Sql .dbml file which auto generates my method signatures for certain stored procedures. eg, I have in SQL spGetEmployees(@Name) so in my data context I have spGetEmployees(string Name). Now, my underlying sp changed to add an additional parameter: spGetEmployees(@name, @count) and so I want the function in my DataConte...

Resharper with large or *very* large files

Hi, I just wanted to know your experience with using resharper. We have a very heavy dbml file as our database has many tables and every time I need to open up that file I start getting lots of exception coming from resharper. Has anyone had that problem before? If yes, what did you do to fix this very ANNOYING problem !?!? Thanks ! An...

LINQ to SQL: Multiple / Single .dbml per project?

I've read Rick Strahl's article on Linq to SQL DataContext Lifetime Management hoping to find some answers on how I would manage my .dbml files since they are so closely related to DataContext. Unfortunately, Rick's article seems to be focused on DataContext lifetime at runtime though, and my question is concerned with how the .dbml's s...

MySql Null DateTime and MS.net are not playing nice.

Heres the issue. I have a table(mySQL) that contains dates and some of them are null. I know that I can use DateTime? or Nullable to allow nulls, but I'm not sure where to set it. What I've tried: I built the class in the dblm. The date propery has the following attributes set: Nullable : True Server Data Type : DateTime Type : NUll...

How do I use sqlmetal to generate an internal (not public) data context

I'd like to use sqlmetal to generate dbml data contexts for my project, but the data context and all classes created are marked as public. As this is supposed to be an API layer I'd like to instead mark many of these classes or at least the context itself as internal. Is there a way to do this in sqlmetal or some other tool without havin...

a newbie question on Linq To Sql

When I do this manually public class AdventureWorks : DataContext { public AdventureWorks(string connection) : base(connection) { } public Table<Contact> Contacts; } [Table(Name = "Person.Contact")] public class Contact { [Column(DbType = "int not null", IsPrimaryKey = true, IsDbGenerated = true)] public int ContactID;...

LINQ to SQL not recognizing new associations?

I have two projects using legacy databases with no associations between the tables. In one, if I create associations in the DBML file, I can reference the associations in LINQ like this: From c In context.Cities Where c.city_name = "Portland" _ Select c.State.state_name (assuming I added the link from City.state_abbr to State.state_ab...

LINQ TO SQL Designer Not Working

After installing vs 2008 sp1 , linq to sql designer is not generating the code, an error message Could not load type ' r' from assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. ...

What is the best solution for migrating Linq DBML tables?

I'm trying to figure out the best way to deal with database updates with Linq. I'd like a clean way to checking database changes. I'd like to use a ruby style migration scripts, but I'd also like to keep everything in sync with the DBML file. What is the best way to do this? Do I need to write a custom solution to do this? ...

DBML changes & source control

Hi all! I'm having some issues with the DBML. Every time the team needs to synchronize changes into SVN, the DBML is changed which generates lots of conflicts. This seems to be related to some rearrangement in the dbml editor, because most of the associationConnector sections in the .dmbl.layout seem to change during development if you ...

Linq to SQL: Why am I getting IDENTITY_INSERT errors?

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field: Cannot insert explicit value for identity column in table 'Rigs' when IDENTITY_INSERT is set to OFF. The only identity field is "ID", which has a value of 0. It's defined in the DBML as: [Column(Storage=...

How can I connect an oracle data base with a dbml file?

Hi, I think the best way to use Oracle with LINQ is to map the data base tables into the dbml file by hand. Am I right? When I have done it, then what? How can i connect the data base with the dbml file? ...

Is it possible to auto-generate my Linq2Sql DBML via a script?

I use Linq2Sql and am tired of recreating the dbml everytime the database changes. Is it possible to script the creation of my model given that I want ALL tables and ALL procs? Ideally it would be part of the build process or a custom tool. A simple "refresh from schema" button would be fine too, but from all I can tell, there is no s...

Visual Studio and LINQ: placing the DBML file in separate directory in the project

My strategy was to keep the project's layout clean. Given that this is a datalayer project, and I'll have a class file for each concerned entity, I thought I would put the .dbml into its own directory. It turns out that locating your .dbml file within a subdirectory turns it into a lower level namespace of sorts. This is a C# class libr...

Mapping a database value to a TimeSpan using dbml

I need to store a time offset in a database column (for example, 12:25 AM, just the time, no date). I would like to use the nice data visual modeling capabilities in Visual Studio 2008 to generate dbml and the code to go with it. The database is Sql Server 2005. Since a TimeSpan is essentially an Int64 (aka long) containing the number ...