How do we give default value to Primary Key fields in websites created through ASP.NET Dynamic Data (Entities) - guid

I am creating ASP.NET Dynamic Data Site (using entities) to manage master tables of my application.
All my master table has a Primary Key of "UniqueIdentifier" in SQL Server. Where should I write "Guid.NewGuid()" in order to give default value (as new Guid) and to show them in textboxes bound with these fields?

ok, I found the solution myself.
We need to open EDMX file, and ID property in each entity needs to be have StoreGeneratedPattern="Computed"

Related

Add navigation property to Membership schema

I have an Entity Data Model for my Web Site that includes a table with some extra data for the registered users (called UserInfo). Currently, I'm setting the id of the new rows of UserInfo using the Membership.GetUser(...).ProviderKey.
What I want to do is to add a navigation property to my UserInfo table to point to the corresponding Membership row for that user but, due I have not the Membership schema in my Entity Designer, I can't figure out how to stablish this link between the tables.
Any idea?
Thanks very much,
Well, I've finally decided it's easier simply to add a property to my UserInfo table (called guid) that store the guid of the MembershipUser schema.

How to create Dynamic table in ms sql?

I have a Membership form in asp.net Which contains custom fields.so by that custom Field User can generate more than one field dynamically
for Example (User can add Mobile number column in their membership form (they can add what ever they need)).So i cant able to maintain static table for Membership control in ms sql.
Is there any way to create dynamic table in ms sql for Dynamic Membership form.(whenever user adding column dynamcally i should get those column in ms sql dynamic table)
please help me to solve my problem

Adding unexisting entities while creating another entity

I'm setting up a blog using Asp.net MVC3 and Entity framework 4. Most of the properties of the blog post already exist in the database, and therefore can easily be linked to the blog post during the creation.
One of the last element I've added are sources, these sources have a direct link to my BlogPost and have to be added during the creation of the BlogPost. My idea was to use the entity property Sources of the BlogPost entity, like:
blogPost.Sources.Add(new Source() { Name = source.Value, Url = source.Key.ToString(), Type = "source" });
Unfortunately I'm not allowed to create and add an Source this way, I'm getting the error: "Cannot insert explicit value for identity column in table 'Source' when IDENTITY_INSERT is set to OFF."
I guess this is cause of the ID column which has is an Identity with Identity increment turned on, but I don't set any ID myself. I tried to make id = null, but since its not a null-able it's not allowed either.
I believe turning this feature off let's me add records with my own ID's, but this is not what I want. The database should create the ID's.
Is there a way to add these kinds of properties during creation?
I solved the problem by adding the Source entity again from the database, apparently the entity framework model was generated before the field was set to Identity Increasing and therefore wanted to insert it's own ID's.

Adding custom fields on asp net membership users table

I have a application which I would like to add custom fields to the users table. I am not sure how to work after adding the columns. The columns are foreign keys to another table which holds more details for the user.
I am using Linq-to-SQL. So every time I add a user (using the membership functions i.e. Membership.CreateUser(..)) I end up calling another service to update the foreign keys on the users table.
Any better way of doing this will be highly appreciated.
Why are you adding foreign keys to the User table, pointing to another table with additional info??
I would do it the other way around:
create your own table UserInfo
create a FK column in UserInfo that points to the row in your ASP.NET membership User table
leave the system-provided User table alone - so you won't run into problems when e.g. an upgrade to the ASP.NET membership system is rolled out.....
I strongly recommend you not to extend secure tables such like Users, Membership, Profile. Better create another one table in your database (not secure database) with full info which you need. Call it 'User' with foreign key to 'Id' of table User in secure database.

Using ASP.NET Dynamic Data / LINQ to SQL, how do you have two table fields have a relationship to the same foreign key?

I am using ASP.NET Dynamic Data for a project and I have a table that has two seperate fields that link to the same foreign key in a different table.
This relationship works fine in SQL Server.
However, in the LINQ to SQL model in the ASP.NET Dynamic Data model, only the first field's relationship is reflected. If I attempt to add the second relationship manually, it complains that it "Cannot create an association "ForeignTable_BaseTable". The same property is listed more than once: "Id"."
This MSDN article gives such helpful advice as:
Examine the message and note the property specified in the message.
Click OK to dismiss the message box.
Inspect the Association Properties and remove the duplicate entries.
Click OK.
The solution is to delete and re-add BOTH tables to the LINQ to SQL diagram, not just the one you have added the second field and keys to.
Alternatively, it appears you can make two associations using the LINQ to SQL interface - just don't try and bundle them into a single association.

Resources