Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:26:59+00:00 2026-06-05T13:26:59+00:00

This is my MVC model: public class Link { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ID {

  • 0

This is my MVC model:

public class Link
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid ID { get; set; }

    [DisplayName("Shorted URL")]
    public string SURL { get; set; }

    [DisplayName("General Link")]
    public string OriginalURL { get; set; }

    [DisplayName("Click Count")]
    public int ClickCount { get; set; }
}

and this is LinkDBContext class:

public class LinkDBContext : DbContext
{
    public DbSet<Link> Links { get; set; }
}

when I want to add some data to database using this code:

    private string GetNewID(string url, string id)
    {
        LinkDBContext Links = new LinkDBContext();
        //id = "http://" + id;
        List<Link> link = Links.Links.Where(a => (a.OriginalURL == id && a.SURL == id)).ToList();
        if (link.Count == 0)
        {
            List<Link> LLinks = Links.Links.ToList<Link>();
            Link li = new Link();
            //li.ID = new Guid();
            li.ClickCount = 0;
            li.SURL = id;
            li.OriginalURL = url;
            Links.Links.Add(li);
            Links.SaveChanges();
            Links.Dispose();
            return id.ToString();
        }

        return GetNewID(url);
    }

I just get an exception that is: Cannot insert the value NULL into column 'ID', table 'GhiasiDB.dbo.Links'; column does not allow nulls. INSERT fails.The statement has been terminated.

what is the problem and how can I resolve it?


update

I changed the type of ID from Guid to int and when I tried again I got this exception from List<Link> LLinks = Links.Links.ToList<Link>(); of GetNewID method:The 'ID' property on 'Link' could not be set to a 'Guid' value. You must set this property to a non-null value of type 'Int32'.
and I don’t know where did it come from. I changed all Guides to int!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:27:01+00:00Added an answer on June 5, 2026 at 1:27 pm

    If you allowed EF to generate the tables it would create the PK with a default value set to (newid()). You can set it manually if you designed the database first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this model : public class Person { public string Name { get;
i have this model on mvc: public class User { public string Name {
This is a MVC 3 project. Just for testing, I have public class MyRoleProvider
I have a very simple MVC app at this point: Controller: public class HomeController
I have an ASP.net MVC model with a date: public class EditModel { [Display(Name=DOB)]
I have model public class UserModel : IUserModel { public LocationModel WorkLocation { get;
I'm a nub in MVC.I've a Model: public class Usuarios { [Required(ErrorMessage = **TxtOPID
I'm following this MVC model: http://java.sun.com/developer/technicalArticles/javase/mvc/ In my model I have an ArrayList shapes
I am using custom model binder in ASP.NET MVC 2 that looks like this:
I am creating a model binder to use with asp.net mvc. This is what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.