sqlmetal

How to read Dbml file and map it into an object model in .net?

Im planning to write a code generator to generate UI (forms, grids, etc.). Since i'm using Linq i'm planning to read dbml file for metadata extraction purposes. I wonder if there is some Api to read the Dbml object model (database, tables, columns, asociations). I've opened SQLMetal.exe with Red Gate's .NET Reflector, it contains a nam...

OneToOne relation (cardinality) in LINQ to SQL with SQLMetal

Is there any possibility to set OneToOne relation (cardinality) when generate dbml with SQLMetal? By default dbml schema generated with the OneToMany relation. ...

All or None with SQLMetal?

I was looking to create a pre-build method for a web application using SQLMetal to bring any changes since the last build into my DBML file. Since we are just starting out with LINQ most of the large database is not in the DBML. Is there any way to use SQLMetal to just regenerate a handful (less than 10) of tables and about 3 SPROCs or...

Is SqlMetal a good solution for mapping to a database that contains *only* tables?

I'm thinking of using SqlMetal to auto-generate LinqToSql code for a simple and small database. The database will have only tables with some primary and foreign keys (i.e., no views, stored procedures, functions, etc.). I'd like to do all joins, grouping, sorting, and advanced data manipulation using Linq. I have experience with LinqToO...

how to force sqlmetal to keep field name case?

When dbml file is generated automatically by Visual Studio I get the exact field names as they appeared in the tables. However, since VS does not provide refresh function for dbml, I run sqlmetal manually to re-create dbml file. It works fine with one exception -- sqlmetal "corrects" the names ses_Id -> Ses_Id aga_Id -> Aga_Id and so...

SqlMetal Not Generating Views, Functions, or Stored Procedures

I am using the following commands as part of a cmd file: sqlmetal /server:localhost\SQLEXPRESS /database:DashBoard /dbml:DataClasses.dbml /namespace:DashBoard.Data sqlmetal /server:localhost\SQLEXPRESS /database:DashBoard /views /functions /sprocs /code:DataClasses.designer.cs /context:DataClassesDataContext /namespace:DashBoard.Data Da...

sqlmetal: how to preserve names for foreign keys without cutting the first name

Sqlmetal creates "embedded" properties for any foreign key it finds for table. Nice. The problem is when I have several foreign keys which refers to the same (foreign) table. This I like: FK_Company_Post then I can write in code: company.Post But this I don't like -- cutting suffixes: FK_Company_Post_HQ FK_Company_Post_Mailing ...

SqlMetal wrongly generates the return type of my stored proc (LINQ)

Hi, Hi have a stored proc that always returns a single row depending of a parameter: IF @bleh = 1 SELECT TOP 1 Xyz FROM Abc ELSE SELECT TOP 1 Def FROM Abc I must use SqlMetal to generate the DataContext but this stored procedure returns a IMultipleResults, which is an error. Instead it should return a ISingleResult... If I remov...

SQL metal to dbml, how to generate correct foreign key column names

I have this 2 tables table name: Person with Columns:PersonID, Name table name: VisitInfo with Columns: VisitPersonID , CoordinatorPersonID both columns have a foreign key to person table When i generate the code i get a VisitInfo class with the properties: Person CoordinatorPerson But what i want is a VisitInfoClass with the ...

How to give table information in the SQl METAL Command Line Tool

Hi All, How do we mention the Table information in the command when we want to generate the external mapping file directly from the database. We have the /Database option but how do we mention the table information ...

SqlMetal, Sql Server 2008 database, Table with HierachyID, dal cs file is created sometimes ?

I have 2 databases with a 2 tables with HierachyID fields. For one database I can get a dal cs file, for the other database I cannot get a dal cs file ? HBus is a database I can get the dal cs for, ... SqlMetal /server:.\SQLSERVER2008 /database:HBus /code:HBusDC.cs /views /functions /sprocs /namespace:HBusDC /context:HBusDataContext ...

Method of saving the row creation time which can be generated by SQLMetal

I'd like to save the creation time of a row, so I have created a datetime column and set it's Default Value to be Getdate(). But when I generate the dbml file from SQLMetal and re-create the database from it, the function is missing. I've added the /functions parameter to the command line when running SQLMetal but this didn't fix the pr...

Executing LINQ Queries In Excel To SQL

I want to be able to interact with an SQL database using LINQ and Excel (it's a legacy thing). Is this sort of thing possible? I'm screwing around with SQLMetal, and have generated some database classes in VB, but they don't seem to go in smoothly into Excel (I'm getting a lot of red error text). Any ideas would be appreciated. ...

SQLMetal DataContext Associations Not Generated

I am generating the LINQ-to-SQL DataContext and entity classes for a database. The database has several tables, two of which are - [AccountMaster] and [AccountCodes]. There is a foreign key relationship defined between them, with [AccountMaster].AccountNumber being referenced from [AccountCodes]. Adding a LINQ-to-SQL file in VS2008 and ...

Does SQLMetal support SQL-Server 2008 datatypes?

I'm using LinqToSQL in a 3.5 framework project in VS2K8, running against MS SQL 2k8. When I create the table mappings using the design surface within Visual Studio everything works fine. When I create the table mappings using SQLMetal (from the Windows SDK v6.1), SQLMetal complains about about the SQL Server 2k8 datatypes (e.g. date an...

SQLMetal fails to generate .cs file from SQL Server 2008 database using geography (spatial) types

We have a SQL Server 2008 database that has recently been updated to use the geography (spatial) type. We use SQLMetal to generate our DAL (LINQ entities) and since the type upgrade, this now fails to produce a .cs file due to a missing type error which causes SQLMetal to abandon the process. Is there a workaround (other the removing th...

SQL Metal for specific tables or another way to refresh/add table to .dbml file

Hi, anybody have any easy way of doing this in Visual Studio, without having to use the Server Explorer ? I tried also looking at macro's but recording only produce Sub TemporaryMacro() End Sub So no luck there. Any way to script this? ...

Model, Business Rules and Persistence

Hello all, I'm having trouble figuring out the best approach for an certain application. I'm not really used to newer architectures that superseded old TLA (three layer architecture), so that's where I'm coming from. When designing the Model and the DAL for my application (POCO classes, right??), I got the following doubts: Should my...

Code generated by sqlmetal makes NOT NULL primary key columns Nullable

I'm using sqlmetal.exe to generate a DataContext class from a sqlserver database to use with LINQ. I have a bunch of stored procedures that in some cases returns a primary key column that is a NOT NULL INT, such as this one: CREATE PROCEDURE spDDIs_Find(@DDINumber VARCHAR(64)) AS IF NOT EXISTS (SELECT ID FROM tDDIs WHERE DDINumber = @D...

How do I update a foreign key efficiently in LINQ to SQL/SQLMetal?

I ran into an issue trying to update a foreign key field: record.ForeignId = newId; It bombs with "Operation is not valid due to the current state of the object" due to SQLMetal code that throws System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(). I was not the first to hit this issue: http://stackoverflow.com/questions/2...