insertonsubmit

How do I get Id of a record without submitting and re-querying?

时光毁灭记忆、已成空白 提交于 2019-12-14 00:42:01
问题 I have an ID that is set to auto increment (int obviously). var dc = new DataContext([STRING]); var usersTable = dc.GetTable<Audit_User>(); var user = usersTable.FirstOrDefault(o => o.Username.Equals("NAME")); if (user == null) { user = new Audit_User() { Username = "NAME" }; usersTable.InsertOnSubmit(user); } //HERE - I need access to the user Id dc.SubmitChanges(); For more context, please see the tags. 回答1: //HERE - I need access to the user Id Actually you do not . If you consistently use

ling to sql: 'MYDataContext' does not contain a definition for 'InsertOnSubmit'

你离开我真会死。 提交于 2019-12-13 03:42:12
问题 I am trying to add a row to a table: MYDataContext dc = new MYDataContext("MYConnectionString"); using (MYDataContext db = new MYDataContext("MYConnectionString")) { NotificationLog n = new NotificationLog(); n.result = result; n.context = message; n.tomobiles = phoneprefix + phone; n.datesent = DateTime.Now; n.SMSprovider = provider; db.InsertOnSubmit(n); db.SubmitChanges(); } But I get this error: 'MYDataContext' does not contain a definition for 'InsertOnSubmit' and no extension method

NullReferenceException when doing InsertOnSubmit in LINQ to SQL

陌路散爱 提交于 2019-12-03 08:22:00
问题 In my database I have a table called StaffMembers when I bring this into my .net Project as through linq-to-sql an entity class StaffMember is created Now I have also created a partial class StaffMember in my project also, to add extra properties that I use in other top layers. eg. IsDeleted property. This partial class also inherits an abstract class and interface to make sure some other properties are also implemented. Now when I create a new instance of "StaffMember" eg. StaffMember

Insert into many-to-many relationship tables

让人想犯罪 __ 提交于 2019-12-02 14:17:48
问题 Simple scenario [ClientTable]: ClientId, ClientName, Phone, Age [CityTable]: CityID, CityName, Country [ClientCityTable]: ClientCityID, ClientID, CityID Client client = new Client("John", 123456789, 40); City city = new City("NY", USA); ClientCity clientCity = new ClientCity(client, city); Should I make InsertOnSubmit on every object(table) or only on clientCity? Or it doesn't matter? Where's the difference? EDIT I'ms asking if should I make DatabaseDC dc = new DatabaseDC(connectionString);

Insert into many-to-many relationship tables

此生再无相见时 提交于 2019-12-02 12:15:32
Simple scenario [ClientTable]: ClientId, ClientName, Phone, Age [CityTable]: CityID, CityName, Country [ClientCityTable]: ClientCityID, ClientID, CityID Client client = new Client("John", 123456789, 40); City city = new City("NY", USA); ClientCity clientCity = new ClientCity(client, city); Should I make InsertOnSubmit on every object(table) or only on clientCity? Or it doesn't matter? Where's the difference? EDIT I'ms asking if should I make DatabaseDC dc = new DatabaseDC(connectionString); dc.Client.InsertOnSubmit(client); dc.City.InsertOnSubmit(city); dc.ClientCity.InsertOnSubmit(clientCity)

Can't find InsertOnSubmit() method

风流意气都作罢 提交于 2019-12-01 05:20:58
I'm new to Entity Framework, and I'm think there is something that I misunderstand here. I'm trying to insert a row in a table, and everywhere I found code example, they call the method InsertOnSubmit(), but the problem is that I can't find anywhere the method InsertOnSubmit, or SubmitChanges. The error tell me: System.Data.Object.ObjectSet do not contain the definition for InsertOnSubmit, ... What I'm doing wrong?? http://msdn.microsoft.com/en-us/library/bb763516.aspx GMR_DEVEntities CTX; CTX = new GMR_DEVEntities(); tblConfig Config = new tblConfig { ID = Guid.NewGuid(), Code = "new config

Can't find InsertOnSubmit() method

核能气质少年 提交于 2019-12-01 04:03:15
问题 I'm new to Entity Framework, and I'm think there is something that I misunderstand here. I'm trying to insert a row in a table, and everywhere I found code example, they call the method InsertOnSubmit(), but the problem is that I can't find anywhere the method InsertOnSubmit, or SubmitChanges. The error tell me: System.Data.Object.ObjectSet do not contain the definition for InsertOnSubmit, ... What I'm doing wrong?? http://msdn.microsoft.com/en-us/library/bb763516.aspx GMR_DEVEntities CTX;