Search Results

Search found 49963 results on 1999 pages for 'entity system'.

Page 26/1999 | < Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >

  • 'Generic' ViewModel

    - by Ian MacPherson
    Using EF 4, I have several subtypes of a 'Business' entity (customers, suppliers, haulage companies etc). They DO need to be subtypes. I am building a general viewmodel which calls into a service from which a generic repository is accessed. As I have 4 subtypes, it would be good to have a 'generic' viewmodel used for all of these. Problem is of course is that I have to call a specific type into my generic repository, for example: BusinessToRetrieve = _repository .LoadEntity<Customer>(o => o.CustomerID == customerID); It would be good to be able to call <SomethingElse>, somethingElse being one or other of the subtypes), otherwise I shall have to create 4 near identical viemodels, which seems a waste of course! The subtype entity name is available to the viewmodel but I've been unable to figure out how to make the above call convert this into a type. An issue with achieving what I want is that presumably the lambda expression being passed in wouldn't be able to resolve on a 'generic' call ?

    Read the article

  • ASP.net MVC 2.0 using the same form for adding and editing.

    - by Chevex
    I would like to use the same view for editing a blog post and adding a blog post. However, I'm having an issue with the ID. When adding a blog post, I have no need for an ID value to be posted. When model binding binds the form values to the BlogPost object in the controller, it will auto-generate the ID in entity framework entity. When I am editing a blog post I DO need a hidden form field to store the ID in so that it accompanies the next form post. Here is the view I have right now. <% using (Html.BeginForm("CommitEditBlogPost", "Admin")) { %> <% if (Model != null) { %> <%: Html.HiddenFor(x => x.Id)%> <% } %> Title:<br /> <%: Html.TextBoxFor(x => x.Title, new { Style = "Width: 90%;" })%> <br /> <br /> Summary:<br /> <%: Html.TextAreaFor(x => x.Summary, new { Style = "Width: 90%; Height: 50px;" }) %> <br /> <br /> Body:<br /> <%: Html.TextAreaFor(x => x.Body, new { Style = "Height: 250px; Width: 90%;" })%> <br /> <br /> <input type="submit" value="Submit" /> <% } %> Right now checking if the model is coming in NULL is a great way to know if I'm editing a blog post or adding one, because when I'm adding one it will be null as it hasn't been created yet. The problem comes in when there is an error and the entity is invalid. When the controller renders the form after an invalid model the Model != null evaluates to false, even though we are editing a post and there is clearly a model. If I render the hidden input field for ID when adding a post, I get an error stating that the ID can't be null. Any help is appreciated. EDIT: I went with OJ's answer for this question, however I discovered something that made me feel silly and I wanted to share it just in case anyone was having a similar issue. The page the adds/edits blogs does not even need a hidden field for id, ever. The reason is because when I go to add a blog I do a GET to this relative URL BlogProject/Admin/AddBlogPost This URL does not contain an ID and the action method just renders the page. The page does a POST to the same URL when adding the blog post. The incoming BlogPost entity has a null Id and is generated by EF during save changes. The same thing happens when I edit blog posts. The URL is BlogProject/Admin/EditBlogPost/{Id} This URL contains the id of the blog post and since the page is posting back to the exact same URL the id goes with the POST to the action method that executes the edit. The only problem I encountered with this is that the action methods cannot have identical signatures. [HttpGet] public ViewResult EditBlogPost(int Id) { } [HttpPost] public ViewResult EditBlogPost(int Id) { } The compiler will yell at you if you try to use these two methods above. It is far too convenient that the Id will be posted back when doing a Html.BeginForm() with no arguments for action or controller. So rather than change the name of the POST method I just modified the arguments to include a FormCollection. Like this: [HttpPost] public ViewResult EditBlogPost(int Id, FormCollection formCollection) { // You can then use formCollection as the IValueProvider for UpdateModel() // and TryUpdateModel() if you wish. I mean, you might as well use the // argument since you're taking it. } The formCollection variable is filled via model binding with the same content that Request.Form would be by default. You don't have to use this collection for UpdateModel() or TryUpdateModel() but I did just so I didn't feel like that collection was pointless since it really was just to make the method signature different from its GET counterpart. Thanks for the help guys!

    Read the article

  • Enumerable.Range in and Expression and Entity Framework

    - by eka808
    I'm currently developping an expression method (used in linq to entity queries) who has to give me a daycount for a given period (start date and end date) decrementing this daycount if specials days are in the period. My idea was the following : Generate an enumerable with all the dates (and with Enumerable.Range) Make a .Where on this enumerable to remove the specials dates Like a MyEnumerable.Where(a = a != "20120101") After that, return a MyEnumerable.Count() I come with this code : return (p) => Enumerable .Range(1, 4) .Where(a => a != 20120101) .AsQueryable() .Count() I tried to cast as a list, as a queryable, both (like the example) and no way ! it doesn't work ! I always get this error : LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[System.Int32] Range(Int32, Int32)' method, and this method cannot be translated into a store expression. Have you got an idea about that ? Using an enumerable is of course not mandatory, any working solutions is good ^^ Thank's by advance !

    Read the article

  • Entity Framework 5, separating business logic from model - Repository?

    - by bnice7
    I am working on my first public-facing web application and I’m using MVC 4 for the presentation layer and EF 5 for the DAL. The database structure is locked, and there are moderate differences between how the user inputs data and how the database itself gets populated. I have done a ton of reading on the repository pattern (which I have never used) but most of my research is pushing me away from using it since it supposedly creates an unnecessary level of abstraction for the latest versions of EF since repositories and unit-of-work are already built-in. My initial approach is to simply create a separate set of classes for my business objects in the BLL that can act as an intermediary between my Controllers and the DAL. Here’s an example class: public class MyBuilding { public int Id { get; private set; } public string Name { get; set; } public string Notes { get; set; } private readonly Entities _context = new Entities(); // Is this thread safe? private static readonly int UserId = WebSecurity.GetCurrentUser().UserId; public IEnumerable<MyBuilding> GetList() { IEnumerable<MyBuilding> buildingList = from p in _context.BuildingInfo where p.Building.UserProfile.UserId == UserId select new MyBuilding {Id = p.BuildingId, Name = p.BuildingName, Notes = p.Building.Notes}; return buildingList; } public void Create() { var b = new Building {UserId = UserId, Notes = this.Notes}; _context.Building.Add(b); _context.SaveChanges(); // Set the building ID this.Id = b.BuildingId; // Seed 1-to-1 tables with reference the new building _context.BuildingInfo.Add(new BuildingInfo {Building = b}); _context.GeneralInfo.Add(new GeneralInfo {Building = b}); _context.LocationInfo.Add(new LocationInfo {Building = b}); _context.SaveChanges(); } public static MyBuilding Find(int id) { using (var context = new Entities()) // Is this OK to do in a static method? { var b = context.Building.FirstOrDefault(p => p.BuildingId == id && p.UserId == UserId); if (b == null) throw new Exception("Error: Building not found or user does not have access."); return new MyBuilding {Id = b.BuildingId, Name = b.BuildingInfo.BuildingName, Notes = b.Notes}; } } } My primary concern: Is the way I am instantiating my DbContext as a private property thread-safe, and is it safe to have a static method that instantiates a separate DbContext? Or am I approaching this all wrong? I am not opposed to learning up on the repository pattern if I am taking the total wrong approach here.

    Read the article

  • How To Create Your Own x86 Operating System for Modern PC Computers

    - by mudge
    I'd like to create a new operating system for x86 PC computers. I'd like it to be 64-bit but possibly run as 32-bit as well. I have these kinds of questions: What kinds of things do you start working on first? Knowing where to start in writing your own operating system seems to me to be a tricky subject, so I am interested in your input. Generally how to go about making your own 32-bit/64-bit operating system, or good resources that mention useful information about going about writing your own operating system for x86 computers. I don't care how old sources are as long as they are still relevant and useful to what I am doing. I know that I will want it to have kernel drivers that access peripheral hardware directly. Where should I look for advice and documentation for programming and understanding the interface to peripheral hardware the operating system will communicate with? I will need to understand how the operating system will receive input and interact with keyboards, mice, computer monitors, hard drives, USB, etc. etc. This is probably the area I know least about. I have the Intel instruction set manuals and have been getting more familiar with assembly programming, so the CPU side of things is what I know the most about. At this point I'm thinking that I'd like to implement the Linux system calls within my operating system so that programs that run on Linux can run on my operating system. I want my operating system to use the ELF binary format. I wonder what obstacles I have to overcome to achieve this Linux compatibility. Are the main things implementing the system calls that Linux provides, and using the ELF format? What else? I am also interested in people's thoughts about why it might not be a good idea to make your own operating system, and why it is a good idea to make your own operating system. Thank you for any input.

    Read the article

  • Entity Framework - An object with the same key already exists in the ObjectStateManager

    - by Justin
    Hey all, I'm trying to update a detached entity in .NET 4 EF: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save(Developer developer) { developer.UpdateDate = DateTime.Now; if (developer.DeveloperID == 0) {//inserting new developer. DataContext.DeveloperData.Insert(developer); } else {//attaching existing developer. DataContext.DeveloperData.Attach(developer); } //save changes. DataContext.SaveChanges(); //redirect to developer list. return RedirectToAction("Index"); } public static void Attach(Developer developer) { var d = new Developer { DeveloperID = developer.DeveloperID }; db.Developers.Attach(d); db.Developers.ApplyCurrentValues(developer); } However, this gives the following error: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key. Anyone know what I'm missing? Thanks, Justin

    Read the article

  • How to manage GetDate() with Entity Framework

    - by wcpro
    I have a column like this in 1 of my database tables DateCreated, datetime, default(GetDate()), not null I am trying to use the Entity Framework to do an insert on this table like this... PlaygroundEntities context = new PlaygroundEntities(); Person p = new Person { Status = PersonStatus.Alive, BirthDate = new DateTime(1982,3,18), Name = "Joe Smith" }; context.AddToPeople(p); context.SaveChanges(); When i run this code i get the following error The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated. So i tried setting the StoreGeneratedPattern to computed... same thing, then identity... same thing. Any ideas?

    Read the article

  • Creating blob properties with Entity Framework 4?

    - by David Veeneman
    I am creating an EF4 model-first application with a WPF UI. One of the controls on my UI is a RichTextDocument, which outputs a WPF FlowDocument. I can either serialize the FlowDocument to a byte array, or extract its XAML markup as a string. I would prefer to use binary serialization, if I can. Here are my questions: If I serialize to a byte array, how do I specify an entity property as a byte array in the EDM Designer? If I extract a XAML markup string, can I specify that the EDM Designer create the corresponding database column as a nvarchar(max) column? As to the second question, I assume I could always manually edit the MyModel.edmx.sql file to change the data type from nvarchar(4000) to nvarchar(max) before executing it, but I would like to know if it can be done in the Designer. Thanks for your help.

    Read the article

  • How do I delete multiple rows in Entity Framework (without foreach)

    - by Jon Galloway
    I'm deleting several items from a table using Entity Framework. There isn't a foreign key / parent object so I can't handle this with OnDeleteCascade. Right now I'm doing this: var widgets = context.Widgets .Where(w => w.WidgetId == widgetId); foreach (Widget widget in widgets) { context.Widgets.DeleteObject(widget); } context.SaveChanges(); It works but the foreach bugs me. I'm using EF4 but I don't want to execute SQL. I just want to make sure I'm not missing anything - this is as good as it gets, right? I can abstract it with an extension method or helper, but somewhere we're still going to be doing a foreach, right?

    Read the article

  • Repository Pattern and Entity Framework.

    - by vitorcast
    Hi people, I want to make an implementation with repository pattern with ASP.NET MVC 2 and Entity Framework but I have had some issues in the process. First of all, I have 2 entities that has a relationship between them, like Order and Product. When I generate my dbml file it gaves me a class Order with a property that map a "ProductSet" and one class Product with a property that map wich Order that Product relates itself. So I create my Repository pattern like IReporitory with the basic CRUD operations and inside my controllers I implement the ProductRepository or OrderRepository. The problem occurs when I try to create Product and have to assign my Order on it, like ProductOne.Order = _orderRepository.Find(orderId); That operation gave me some strange behavior and I can't find out what is wrong with it. Thanks for the help.

    Read the article

  • Entity Framework inheritance: TPT, TPH or none?

    - by silverfighter
    Hi, I am currently reading about the possibility about using inheritance with Entity Framework. Sometimes I use a approch to type data records and I am not sure if I would use TPT or TPH or none... For example... I have a ecommerce shop which adds shipping, billing, and delivery address I have a address table: RecordID AddressTypeID Street ZipCode City Country and a table AddressType RecordID AddressTypeDescription The table design differs to the gerneral design when people show off TPT or TPH... Does it make sense to think about inheritance an when having a approach like this.. I hope it makes sense... Thanks for any help...

    Read the article

  • Asp.net ADO.NET Entity Framework or ADO.NET

    - by sharru
    I'm starting a new project based on ASP.NET and Windows server. The application is planned to be pretty big and serve large amount of clients pulling and updating high freq. changing data. I have previously created projects with Linq-To-Sql or with Ado.Net. My plan for this project is to use VS2010 and the new EF4 framework. It would be great to hear other programmers options about development with Entity Framework Pros and cons from previous experience? Do you think EF4 is ready for production? Should i take the risk or just stick with plain old good ADO.NET?

    Read the article

  • Entity Framework One-To-One Mapping Issues

    - by Baddie
    Using VS 2010 beta 2, ASP.NET MVC. I tried to create an Entity framework file and got the data from my database. There were some issues with the relationships, so I started to tweak things around, but I kept getting the following error for simple one-to-one relationships Error 1 Error 113: Multiplicity is not valid in Role 'UserProfile' in relationship 'FK_UserProfiles_Users'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *. myEntities.edmx 2024 My Users table is consists of some other many-to-many relationships to other tables, but when I try to make a one-to-one relationship with other tables, that error pops up. Users Table UserID Username Email etc.. UserProfiles Table UserProfileID UserID (FK for Users Table) Location Birthday

    Read the article

  • Using LIKE operator in LINQ to Entity

    - by Draconic
    Hi, everybody! Currently in our project we are using Entity Framework and LINQ. We want to create a search feature where the Client fills different filters but he isn't forced to. To do this "dynamic" query in LINQ, we thought about using the Like operator, searching either for the field, or "%" to get everything if the user didn't fill that field. The joke's on us when we discovered it didn't support Like. After some searching, we read several answers where it's sugested to use StartsWith, but it's useless for us. Is the only solution using something like: ObjectQuery<Contact> contacts = db.Contacts; if (pattern != "") { contacts = contacts.Where(“it.Name LIKE @pattern”); contacts.Parameters.Add(new ObjectParameter(“pattern”, pattern); } However, we'd like to stick with linq only. Happy coding!

    Read the article

  • ADO.NET Entity Framework or ADO.NET

    - by sharru
    I'm starting a new project based on ASP.NET and Windows server. The application is planned to be pretty big and serve large amount of clients pulling and updating high freq. changing data. I have previously created projects with Linq-To-Sql or with Ado.Net. My plan for this project is to use VS2010 and the new EF4 framework. It would be great to hear other programmers options about development with Entity Framework Pros and cons from previous experience? Do you think EF4 is ready for production? Should i take the risk or just stick with plain old good ADO.NET?

    Read the article

  • Best Practices - Data Annotations vs OnChanging in Entity Framework 4

    - by jptacek
    I was wondering what the general recommendation is for Entity Framework in terms of data validation. I am relatively new to EF, but it appears there are two main approaches to data validation. The first is to create a partial class for the model, and then perform data validations and update a rule violation collection of some sort. This is outlined at http://msdn.microsoft.com/en-us/library/cc716747.aspx The other is to use data annotations and then have the annotations perform data validation. Scott Guthrie explains this on his blog at http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx. I was wondering what the benefits are of one over the other. It seems the data annotations would be the preferred mechanism, especially as you move to RIA Services, but I want to ensure I am not missing something. Of course, nothing precludes using both of them together. Thanks John

    Read the article

  • False Duplicate Key Error in Entity Framework Application

    - by ProfK
    I have an ASP.NET application using an entity framework model. In an import routine, with the code below, I get a "Cannot insert duplicate key" exception for AccountNum on the SaveChanges call, but when execution stops for the exception, I can query the database for the apparently duplicated field, and no prior record exists. using (var ents = new PvmmsEntities()) { foreach (DataRow row in importedResources.Rows) { var empCode = row["EmployeeCode"].ToString(); try { var resource = ents.ActivationResources.FirstOrDefault(rs => rs.EmployeeCode == empCode); if (resource == null) { resource = new ActivationResources(); resource.EmployeeCode = empCode; ents.AddToActivationResources(resource); } resource.AccountNum = row["AccountNum"].ToString(); ents.SaveChanges(true); } catch(Exception ex) { } } }

    Read the article

  • ROO: how to create composit primary key in Entity

    - by Paul
    Hi, What can I do if I need to create entity for a table in production DB (Oracle 10g) with composite primary key. For example: [CODE] CREATE TABLE TACCOUNT ( BRANCHID NUMBER(3) NOT NULL, ACC VARCHAR2(18 BYTE) NOT NULL, DATE_OPEN DATE NOT NULL, DATE_CLOSE DATE, NOTE VARCHAR2(38 BYTE) ); CREATE UNIQUE INDEX PK_TACCOUNT ON TACCOUNT (BRANCHID, ACC); I don't want to change the structure of this table. Is it possible to create an "id" field using roo commands? I use Spring Roo 1.0.2.RELEASE [rev 638] Paul

    Read the article

  • Using DataAnnotations with Entity Framework

    - by dcompiled
    I have used the Entity Framework with VS2010 to create a simple person class with properties, firstName, lastName, and email. If I want to attach DataAnnotations like as is done in this blog post I have a small problem because my person class is dynamically generated. I could edit the dynamically generated code directly but any time I have to update my model all my validation code would get wiped out. First instinct was to create a partial class and try to attach annotations but it complains that I'm trying to redefine the property. I'm not sure if you can make property declarations in C# like function declarations in C++. If you could that might be the answer. Here's a snippet of what I tried: namespace PersonWeb.Models { public partial class Person { [RegularExpression(@"(\w|\.)+@(\w|\.)+", ErrorMessage = "Email is invalid")] public string Email { get; set; } /* ERROR: The type 'Person' already contains a definition for 'Email' */ } }

    Read the article

  • Entity Framework Custom T4 Template

    - by s7orm
    Hello, I am using the Entity Framework 4.0 and I am trying to extend my POCO classes generated by the standart T4 template with some custom properties. The classes which are generated by default from EF (without T4) contain 2 properties for every navigation property - NavigationPropertyId and navigationPropertyReference. What I am trying to do is basically extend the generated POCO class with an "Id" property of the foreign key object. I know that I can do that by editing the POCO t4 template. However I have no idea how I can populate/persist the property - I guess I have to somehow extend/modify the method than converts the object to a sql query and vice versa, but I have no idea where to start. Can anyone help? Edit: I just found out, that the EF team has planned to implement something like this - http://blogs.msdn.com/efdesign/archive/2010/03/10/poco-template-code-generation-options.aspx (see Basic POCO with/without Fixup), however this can take ages, so I rather implement it myself.

    Read the article

  • Binding custom property in Entity Framework

    - by deverop
    I have an employee entity in my EF model. I then added a class to the project to add a custom property public partial class Employee { public string Name { get { return string.Format("{0} {1}", this.FirstName, this.LastName); } } } On a aspx form (inside a FormView), I want to bind a DropDownList to the employee collection: <asp:Label runat="server" AssociatedControlID="ddlManagerId" Text="ManagerId" /> <asp:DropDownList ID="ddlManagerId" runat="server" DataSourceID="edsManagerId" DataValueField="Id" DataTextField="Name" AppendDataBoundItems="true" SelectedValue='<%# Bind("ManagerId") %>'> <asp:ListItem Text="-- Select --" Value="0" /> </asp:DropDownList> <asp:EntityDataSource ID="edsManagerId" runat="server" ConnectionString="name=Entities" DefaultContainerName="Entities" EntitySetName="Employees" EntityTypeFilter="Employee" EnableFlattening="true"> </asp:EntityDataSource> Unfortunately, when I fire up the page, I get an error: DataBinding: 'System.Web.UI.WebControls.EntityDataSourceWrapper' does not contain a property with the name 'Name'. Any ideas what I'm doing wrong?

    Read the article

  • Correct way to perform an update using ADO.Net Entity Model in .net 4

    - by sf
    Hi, I just wanted to clarify if this is the appropriate way to perform an update using a designer generated ADO.NET Entity Model. I was wondering if there was a way to perform an update without creating the sqlMenu object. public class MenusRepository { public void UpdateMenu(Menu menu) { // _context is instantiated in constructor Menu sqlMenu = (from m in _context.Menus where m.MenuId == menu.MenuId select m).FirstOrDefault(); if (sqlMenu == null) throw new ArgumentException("Can't update a Menu which does not exist"); // associate values here sqlMenu.Name = menu.Name; _context.SaveChanges(); } }

    Read the article

  • In separate data access & business logic layer, can I use Entity framework classes in business layer

    - by Greg
    In separate data access & business logic layer, can I use Entity framework classes in business layer? EDIT: I don't think I will need to swap out the data access layer from my business logic in the future (i.e. will be SQL Server), however I will for the UI layer. Therefore the question is more meant to be are there any major issues with using EF classes for me in the business layer? Seems like there would be less plumbing code.

    Read the article

  • Entity Framework Model with inheritance and RIA Services

    - by TimothyP
    Hi, We have an entity framework model with has some inheritance in it. The following example is not the actuall model, but just to make my point... Let's say Base class: Person Child classes: Employee, Customer The database has been generated, the DomainService has been created and we can get to the data: lstCustomers.ItemsSource = context.Persons; EntityQuery<Person> query = context.GetPeopleQuery().Take(4); context.Load(query); But how can I modify the query to only return Customers ?

    Read the article

  • Changing database structure at runtime with Entity Framework?

    - by Teddy
    Hi. I have to write a solution that uses different databases with different structure from the same code. So, when a user logs to the application I determine to which database he/she is connected to at runtime. The user can create tables and columns at any time and they have to see the change on the fly. The reason that I use one and the same code the information is manipulates the same way for the different databases. How can I accomplish this at runtime? Actually is the Entity Framework a good solution for my problem? Thanks in advance.

    Read the article

< Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >