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?
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?
SqlMetal Include worked like a charm for me. First Create a complete dbml file using SqlMeta - Say testComplete.dbml
Now provide this file as an input to SqlMetaInclude SqlMetalInclude /dbml:"testComplete.dbml" /output:"testSubSet.dbml" /include:dbo.SampleTable1=SampleTable1,dbo.SampleTable2=SampleTable2
Note that this tool in has a GUI included which can handle the complete process.
I am using a batch script similar to this to manage the updating of my models when the underlying tables/views change. To use it:
Generate.bat:
sqlmetal /conn:"Data Source={Hostname};Initial Catalog={DBName};User ID={Username};Password={Password}" /dbml:temp.dbml /views
setlocal EnableDelayedExpansion
set file=chosenEntities.txt
set include=
FOR /F %%i IN (%file%) DO (
set include=!include!%%i,
)
set include=%include:~0,-1%
sqlmetalinclude -dbml:temp.dbml -output:ChosenEntities.dbml -include:%include%
sqlmetal /context:CustomDataContext /pluralize /namespace:MyNamespace.DB /language:csharp /code:DBEntities.cs /entitybase:DBEntityBase ChosenEntities.dbml
chosenEntities.txt example:
Accounts
Customers
PRODUCTS_VIEW
AnotherTable
Explanation:
There is one good utility out there which helps you update your existing DBML files from the database: Huagati DBML/EDMX tools.
It's not free, but worth the investment for any serious Linq-to-SQL development.
The only alternative would be to write it yourself - read the database structure and compare that to the XML representation in the DBML, and update the DBML as needed.