ADO.NET :: Generate Id For Set Of Entities When Inserting?
Dec 23, 2010
I have I method where I insert muliple records to a SQL Server 2008 database. The table in which the records are inserted has a primary key integer column with auto increment. The problem is that I have another column called GroupId where I want an integer representing the current insert to be set, i.e. for each time the method gets called a new group id should be generated the group id column of the records to be inserted should be set to this value. What's the best way to generate this group id? I guess I could do a SELECT MAX(GroupId) + 1 FROM Table to generate an id before I make the inserts but this won't be a good solution when it comes to concurrency.
View 13 Replies
Similar Messages:
Aug 11, 2010
have already used the latest technology in a professional manner. NETBasically I have two tables related 1 to 1:the Users table and the table ProfiloPersonale is the key to the Users table that this table are ProfiloPersonale iduser and type uniqueidentifier and diagram sql server 2008 I can clearly see the report, I also did a test to insert a record in the users table ( fictional) directly from sql server and everything works.With LINQ to Entities does not work:The entities 'LEntities.Users' part of the eport 'ProfiloPersonale'.Found 'ProfiloPersonale' related to 0.Expected 1 'ProfiloPersonale'Of course what I am doing is to first create the user and then create their profile in the db, taking the id of the registered
View 1 Replies
Feb 27, 2011
I'm trying to create a view that will allow me to create an entity record and also child entities for that record. I have an entity type called "Parent" and I have a child entity called "Child". I want to be able to allow the user to create a Parent including adding several Children and their details, and the npost them all back to the controller from a single view. I found an example on how I would kind of do something like this here: [URL]. The problem with that example is that you can't refer to entities using bracket notation so it only works for those lists. Is there a way to insert hierarchical entity data using MVC from a single view in a single post back?
View 3 Replies
Mar 5, 2010
Inserting Related Entities?
View 14 Replies
Dec 20, 2010
in an mvc controller i need to insert the input data of the user, but that info is splitted in differents entities(differents related tables in the database, but not all tables are related), and i need to insert all info in a same transaction,(so that if one throws an insertion error or another error, undo all the previous changes maded ) how can afford that? or what is the best way to do that?
i am using a project for a repository, just basic data access stuff, a service project that implement my business logic, and my mvc project.
now i am inserting each entity separately, but if any error occurs, all the previous changes to the error still in the db, so with the time i ll have a very dirty db.
View 17 Replies
Nov 16, 2010
I have a datamodel with a couple of tables. One of my tables have about 40 fields (I know that is a lot, but we have to keep the structure in place as we are upgrading a classic ASP project to MVC). Some of my Actions only updates 1 or 2 fields in my table.
Is there a way to create Entities, for instance, that only contains the contact details of the client table, and not any other details, and then another entity that contains only the address details. I don't want to submit the entire row when I only update telephone details, or the client's picture.
View 1 Replies
Sep 28, 2010
We are starting a new web based product in which we are planning to expose our business logic through WCF services. We will be using ASP.NET 4.0, C#, EF 4.0. In future we want to build iphone applications and WPF applications based on the services. I have been reading a lot about using POCO vs Self Tracking Entities (STE) and from my understand the STEs do not work well with the web scenario.
View 3 Replies
Dec 16, 2010
Windows 7 Ultimate 64bit Visual Studio 2008 Team System Using C# SQL Server 2005 Express Management Studio (Service Pack 3) By using Visual Studio 2008,I opened Server Explorer and tried to modify Database connection,i wanted to use SQL Authentication,I entered User name and Passwored after pressing OK button,i got the following... Error message Failed to generate a user instance of SQL Server.Only an integerated connection can generate a user instance.The connection will be closed.
View 4 Replies
Sep 25, 2010
How to use Stored Procedures with Linq to Entities? I prefer an example with input and output The videos on asp.net only show how to do this with Linq to SQL.
View 5 Replies
May 13, 2010
I have a simple join:
SELECT * FROM MessageAlerts AS A LEFT OUTER JOIN Contacts AS C ON A.ContactId = C.Id LEFT OUTER JOIN
Users AS U ON A.UserId = U.Id INNER JOIN Businesses AS B ON B.Id = C.BusinessId OR B.UserId = U.Id
how to do this : ON B.Id = C.BusinessId OR B.UserId = U.Id with linq in entity framework.
View 2 Replies
Jan 27, 2010
WHY are all the examples on this site linq to SQL? Did ms not themselves announce dropping support for l2SQL over a year ago? i really don't get it. Examples are great.. but really not helping me since i've gone ahead and listened to MS. And can someone at MS clarify what the position is for linq 2 SQL.. Is it supported? Recommended? What the hell.
View 7 Replies
Mar 9, 2011
I use Linq To Entities to get 2 objects m1 & m2. And I don't understand why 2 different objects reference the SAME Template table.
I suspect that the reason due to the connection between MConfigOnPage1, MConfigOnPage2 with MConfiguration. Maybe it should be splitted somehow?
Here I attached my ERD and the code.
[Code]....
View 2 Replies
Feb 19, 2011
I make ASP.NET MVC3 application for spa and I've encoutered problem with M:N relationship. I've got this model Each Insurance Company has different pricing for each patient medical indication, so sample data looks like this:
IC
Indication
Patient
IC1
Indication1
Patient1
Patient2
Indication2
Patient3
[Code]....
And I don't know how to make Edit with possibility of changing not only Indication but IC to.
View 1 Replies
Aug 11, 2010
Having the following model Admin and AdminGroup is joined by AdminAdminGroup which has (AdminId, AdminGroupId) fields. When I add a new Admin row AdminGroups are associated with it automatically however this only works on INSERT.When I'm trying to update or associate more AdminGroup's with particualr Admin row (_repo.Update((DataLayer.Admin)row);) only Admin gets updated and no groups are ever modified.What is the correct way of updated "related" entities? so that AdminGroup also get's updated.
View 6 Replies
Mar 28, 2011
i am having a little problem in mapping all the entities in contained in the namespace "nhibernateTest.Domain" . it basically contains all the Map Classes like , StudentMap, DepartmentMap etc. .. now in case of normal nhibernate what we used to do is :
[Code]....
now what it used to do is . look for all the "*.hbm.xml" files in my namespace and automatically map them...
how to do the same for fluent nHibernate ? so that it looks for all map classes in folder
"nhibernateTest.Domain" ...resolve the namespace "nhibernateTest.Domain"... and automatically map them so that i dont have to create the session separately for diffrent Map classes ?
View 1 Replies
Apr 20, 2010
I have the following admx:
I have to add the (AccData, CntactData, PhnNumber, FnclDetail)entities to the database in one shot
What's the best practices to do the add operation for the above entities??
View 2 Replies
Nov 10, 2010
I am trying to learn LINQ to entities, and am working out how to best structure my BLL layer. I have generated the entity model and have created a generic repository in my DAL that returns results as IList<T>. I initially created the BLL to also return
results as IList<T>:
public IList<DAL.Customer> SelectAll()
{ [code]...
Now I am working on the aspx page, and I can create an ObjectDataSource and configure it to use my BLL, but since I am returning IList, I can't sort since I am not using a DataView. I have seen some articles on the web for converting IList to DataView, but that seems like a lot of overhead for every query.My goal is to keep a clean separation between layers without making things overly complicated. I would like to know how others have done this, or maybe a link to a good tutorial that shows how to structure all three layers.
View 8 Replies
May 13, 2010
I have the following code for the SelectedIndexChanged event of a drop down list. This works fine as it is but this entity has a relationship to another entity (Genre). if i change the select statement to { m, m.Genre.MovieGenre }).ToList(); it doesnt work as contains anonomyous types.
[code].....
View 1 Replies
Apr 15, 2010
I typically don't play with betas, so I am just now getting used to vs 2010 pro. I grabbed it from DreamSpark yesterday, and so far I like all the changes.
I was wondering though, with some of the changes to ado.net EF, is there now a way to set a coding namespace for both the context as well as the entities, instead of just setting the custom tool namespace (this wraps both context and entities)? Typically, I like having my classes grouped into namespaces by type, and since a context isn't an entity, it shouldn't go in the entities namespace. note: I am talking about actual coding namespaces, not the conceptual namepsaces used internally by EF.
I was also wondering if having this (the x86 vs 2010 ide) beside my old one (x64 vs 20080 ide) would pose any problems? It seems to be working ok, I just wanted to make sure I hadn't missed announcements saying I had to de-install one before installing the other.
View 2 Replies
Mar 8, 2011
I am building a web application in asp.Net 4.0 and entity framework. I am trying to retrieve a list of products based on a collection of id's. I first gather all the id's in a collection and then pass it to the linq query. I am trying to get a functionality similar to the IN clause in SQL. The problem seems to be with the Contains() method in the Linq to entities query. Here is my Linq code:
[Code]....
I got the above Linq to entities method from here: [URL]
View 2 Replies
Feb 8, 2011
I use the ObjectDataSource in an ASP.NET Application.
Using the ASPxGridView. When Updating it goes back to the Data Access Layer and tries to update the Entity, now as I can see while having some properites (Columns, Visible = false) when the entity arrives in the update method the visible = false columns have no values.
I don't want to show all the columns...what if I need 3 of the 30 columns? So I thought I would get the original entity from the context and merge the differences from the updated entity.
View 1 Replies
Oct 11, 2010
I am currently trialing EF4 code-first. My POCO classes inherit from an Audit class that contains CreatedBy, CreatedOn, UpdatedBy, UpdatedOn. I was hoping the framework would include the Audit properties in my Action table when creating my database, however this doesn't appear to be the case. Does anyone know how to enable this without overriding the OnModelCreating() method?
Public Class Audit
Public Property CreatedOn as DateTime
End Class
Public Class Action
inherits Audit
Public Property ActionId As Int32
End Class
View 1 Replies
Mar 30, 2010
I am currently developing some user controls so that I can use them at several places within a project. One control is a about editing a list of addresses for a customer. Since this needs to be done at several places within the project I want to make it a simple user control. The user control contains a repeater control. By default the repeater displays one address item to be edited. If more addresses need to be added, the user can click on a button to append an additional address to be entered. The user control should work for creating new addresses as well as editing existing ones.
The address business entity looks something like this:
public class Address
{
public string Street { get; set; }
public City City { get; set; }
public Address(string street, City city)
{
Check.NotNullOrEmpty(street);
Check.NotNull(city);
Street = street;
City = city;
}
}
As you can see an address can only be instantiated if there is a street and a city.
Now my idea was that the user control exposes a collection property called Addresses.The getter of this property collects the addresses from the repeater and return it in a collection. The setter would databind the addresses to be edited to the repeater.
Like this:
public partial class AddressEditControl : System.Web.UI.UserControl
{
public IEnumerable<Address> Addresses
{
get
{
IList<Address> addresses = new List<Address>();
// collect items from repeater and create addresses
foreach (RepeaterItem item in addressRepeater.Items)
{
// collect values from repeater item
addresses.Add(new Address(street, city));
}
return addresses;
}
set
{
addressRepeater.DataSource = value;
addressRepeater.DataBind();
}
}
}
First I liked this approach since it is object oriented makes it very easy to reuse the control. But at some place in my project I wanted to use this control so a user could enter some addresses. And I wanted to pre-fill the street input field of each repeater item since I had that data so the user doesn't need to enter it all by his self.
Now the problem is that this user control only accepts addresses in a valid state (since the address object has only one constructor). So I cannot do:
IList<Addresses> addresses = new List<Address>();
addresses.Add(new Address("someStreet", null)); // i dont know the city yet (user has to find it out)
addressControl.Addresses = addresses;
So the above is not possible since I would get an error from address because the city is null.
Now my question: How would I create such a control? ;)
I was thinking about using an Address DTO instead of a real address, so it can later be mapped to an address. That way I can pass in and out an address collection which addresses don't need to be valid.
Or did I misunderstood the way user controls work?
View 1 Replies
Jun 22, 2010
I have a message table that self joins to itself where Message.ID == Message.Parent. So I have 1 Message with several ChildMessages. This is set up nicely with a Navigation property.
The code is currently:
var message = from m in soe.Messages.Include("ChildMessages")
where m.ID == id
&& m.IsActive
select m;
return message.FirstOrDefault();
What I really want is to only return 1 Message (that is equal to a particular ID and isActive) with all of its Active ChildMessages and I want to do it in one call to the database.
View 2 Replies
Sep 22, 2010
i am working on POCO entities. i had a requirement to provide Edit feature for parent and respective Child records in single View.
Eg: Parent-Customer, Child-Order tables
when updating the parent entity by using => UpdateModel(CustomerIns);
and updating the child entity by using => TryUpdateModel(CustomerIns.Order, "Orders");
The Child Controls Names are like Orders[0].OrderID,Oders[0].OrderDate,etc
The Parent and Child Entities are updating when UpdateModel() is called but when saving Changes by calling Context.SaveChanges() i am getting exception like:
"The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted."
View 3 Replies