我使用实体框架将新对象添加到数据库中。 我使用这些行,但它没有添加对象。
Location location = new Location() { Standort = "new Location" };
db.Location.Add(location);
db.SaveChanges();
表格看起来像这样。
CREATE TABLE [dbo].[Location] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Standort] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
我的联系:
private DatabaseEntities db = new DatabaseEntities();
<connectionStrings>
<add name="DatabaseEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\Database.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />