Is there a way to let linqpad know that a field is a primary key? - linqpad

I have a table called logs, it has a primary key but is not defined as such.
If I want to use LinqPad to update said table's data, I have to set the table to actually have a primary key.
If I was using LinqToSql within visual studio I could modify the mapping to get round this...
I would like to know if the same is possible within LinqPad so that I don't have actually change the database itself.

No - you must define a primary key in the database. LINQPad follows convention over configuration in this respect.
The other option is to generate a typed datacontext in Visual Studio and then tell LINQPad to use that typed datacontext. After clicking Add Connection, choose 'Use a typed datacontext from your own assembly'.

Related

Add References to External Database in Visual Studio 2013

I need to include a Stored Procedure in Visual Studio 2013 which references another Database which is not part of the solution. I only refer to a very small portion of the external database which is itself big and complicated.
I know I need to add a reference to it so that I don't get warnings when referring to objects within the external database from within the Stored Procedure.
Adding that Database to a this or another Solution is not an option as its not part of our solution and importing that creates a whole variety of other issues.
I can see in older versions of Visual Studio that I need to create a schema file using VSDBCMD but this has been replaced by SQLPackage, but I can't see how to access that and whether it will need the external database anyway.
I've been going round in circles on this, so some pointers would be warmly welcomed.
I realize I am late to the party on this but perhaps it will still be useful to someone: You don't mention if this is a c# project or a database project.
I'll assume database as I not sure how you'd get errors otherwise on the internals of an SP.
The only way I know of to remove errors on cross-database references is to add the other database as a project in the database solution, add a database reference to the project with the sp, and then instead of using Database.schema.table syntax in the sp change it (in the database project) to [$(database)].schema.table
Alternately, a DACPAC can be created on the referenced database and used instead of referencing the database in an added project.
I'm new to this stuff myself, but I work with a lot of database cross-references in my sps so I am working through how to address this in database projects

Updating the database - MVC3, Entity framework 4.1

I have an application that uses a database with one table currently. I want to add another column to the table. According to this post(http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part7-cs), there are 2 ways to modify the database: 1. Have EF drop and recreate the db or 2. Explicitly modify the db. Unfortunately, they go over the first method.
What is the correct / easiest way to do the second method if I have a table called Team?
The columns I have are TeamID, TeamAbbreviation, TeamCity, TeamName and TeamDisplayName. I want to add TeamSmallLogoUrl.
To do the second method, just go modify the DB and add your column. Then open the EDMX file in VS (double-click it in the Solution Explorer) and right-click on it when it opens up then choose "Update Model from Database" from the context menu. Click Finish. It'll pick up your added column.
Assuming you are using code-first (hence the EF-4.1 title):
If you are still in development phase and there are no important data in the database, use the Drop-Recreate method. (this is also the easiest way).
If you have some data in the database, just do this manually. The names of the properties and class should match/map directly unto your database schema. (if not mapped, EF will throw an error anyways)

can't find SQL code for XSD schema tables

The following snippet below came from a *.xsd (XML Schema built in Visual Studio) file. I'm trying to figure out where the SQL code lives for the data that can be retrieved with these Strongly Typed .NET tables. I looked everywhere, and cannot find it. Only two of the tables match actual table names in my database. Are these primary and foreign keys configured in Visual Studio for this XSD or are these keys found in the SQL database? If I double click the *.xsd, I can see the tables, but I don't know what data is queried from the database unless I use the SQL profiler. If someone can explain, that would be great.
Found this PDF to be the best resource online so far:
http://oreilly.com/catalog/visualstudiohks/chapter/hack49.pdf
Strongly Typed Datasets starts on page 49. The only problem is that it isn't helping me answer the question I had. When I drag a table from the Server Explorer to the *.xsd file, a TableAdaptor gets created with a method called Fill,GetData(). When created manually, this doesn't get created. It also says it automatically updates the web.config file with connection string information. However, the tables I'm trying to figure out don't have this TableAdaptor. The keys don't seem to be related to SQL at all. They are purely based on the Table in the Visual Studio XSD Designer based on columns created there. I'd still like to know how the data is ultimately mapped to SQL and to what tables.

Is there a way to make Identity Specification show up in the table designer next to the Allow Nulls column?

I would like to be able to see the Identity Specification (not as worried about seed/increment) and hate having to scroll around on the column properties panel.
Is it possible to add a column next to Allow Nulls in the table designer for Identity Specification? Specifically I am concerned with MS SQL Management Studio 2008.
Not exactly what you wanted but you can do it on a database diagram by right clicking the table -> Table View -> Custom and Modifying Custom to include the Identity Specification.
I usually script the table to see all its properties. There are other things that are better vissible when a table is scripted as opposed to opened in designer, like keys and exact constraint definitions. I would recommend that you look at tables in their native format, not wrapped by designer.

Does nHibernate allow drag and drop automatic class creation like linq to sql?

Just a basic question. Learning Linq to SQL and some nHibernate. I am using the mvc tutorial and they drag and drop tables onto the visual studio designer to create the classes and wire up everything.
When I experimented with nHibernate I had to do lots with xml files. Does nHibernate have anything that is "easy" like Linq to SQL or is this drag and drop for Linq to SQL so basic that when I want to do something "real" it won't matter that Visual Studio does this for me (at this basic level)? In other words, the further I go with Linq to SQL, I'll eventually have to handle config files like I do with nHibernate.
Look at Castle's ActiveRecord framework. It replaces the use of XML config files with the use of Attributes directly on the class/property declaration. Also, a tool called ActiveWriter integrates with Visual Studio and allows connecting to a data source and generating the object model!
There is no "native" support like you see with LINQ to SQL. However, there are third party add-ins that will allow you to do something similar with nHibernate. My favorite is this one:
http://sourceforge.net/projects/nhibernateaddin
To use it:
Create a data connection to a
database that contains the structure
you are going to code against (your
development database).
Add a new NHibernate plug-in item
(via add new item) to your project
that will contain you domain objects.
In the property window add the data
connection string from the data
connection you just created (this
isn't automated yet).
Finally, you drag and drop your tables
from your data connection to the
NHibernate plug-in object and when
saved your mapping files and you
domain objects are generated. To use
it you create a data connection to a
database that contains the structure
you are going to code against (your
development database).