Search Results

Search found 9916 results on 397 pages for 'entity component'.

Page 108/397 | < Previous Page | 104 105 106 107 108 109 110 111 112 113 114 115  | Next Page >

  • cache_counter for habtm

    - by piemesons
    Hello How can use cache_counter in a habtm. For example a question has many tags and a tag can belong to many questions. question habtm tags Now i want to find out number of questions belonging to every tag. One way is counting everytime. But, in case of one_to_many i done same thing in this way. Like one question has many answers. then in answer model i specified belongs_to :question,:cache_counter=>true It solved my problem. So how to do the same in habtm.

    Read the article

  • beginner Linq syntax and EF4 question

    - by user564577
    Question With the following linq code snip I get a list of clients with address filtered by the specifications but the form of the entities returned is not what i had expected. The data is 1 client with 2 addresses and 1 client with 1 address. The query returns 3 rows of clients each with 1 address Client 1 = Address1 Client 1 = Address2 Client 2 = Address3 var query = from t1 in context.Clients.Where(specification.SatisfiedBy()).Include("ClientAddresses") join t2 in context.ClientAddresses.Where(spec.SatisfiedBy()) on t1.ClientKey equals t2.ClientKey select t1; My expectation was a little more like a list with only two clients in it, one client with a collection of two addresses and one client with a collection of one address. Client 1 = Address1 / Address2 Client 2 = Address3 What am I missing??? Thanks!

    Read the article

  • ASP.NET MVC 3 NOT showing appropriate view, action called using jquery

    - by TunAntun
    I have a small problem. My action is : public ViewResult SearchForRooms(int HotelDDL) { List<Room> roomsInHotel = bl.ReturnRoomsPerHotel(HotelDDL); return View(roomsInHotel); } Here is the jquery that is calling the action: <script type="text/javascript" language="javascript"> $(document).ready(function () { $("#HotelDDL").change(function () { var text = $("#HotelDDL option:selected").text(); var value = $("#HotelDDL option:selected").val(); alert("Selected text=" + text + " Selected value= " + value); $.post("/Home/SearchForRooms", { HotelDDL: $("#HotelDDL option:selected").val() }); }); }); </script> And finally, here is the View that should be called: @model IEnumerable<RoomReservation.Entities.Entities.Room> @{ ViewBag.Title = "Search"; } <h2>Result</h2> <table> <tr> <th> City </th> <th> Hotel </th> <th> Room label </th> <th> Number of beds </th> <th> Price per night </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelitem=>item.Hotel.City.Name) </td> <td> @Html.DisplayFor(modelItem => item.Hotel.Name) </td> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.NumberOfBeds) </td> <td> @Html.DisplayFor(modelItem => item.PricePerNight) </td> </tr> } </table> Everthing is working ok (databse return all rooms correctly) except final view rendering. I have tried Phil's tool but it doesn't give me any suspicious hints: RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes); So, why is it not showing after jscript send it's post method to SearchForRooms()? Thank you P.S. If you need any other piece of code please just say so.

    Read the article

  • Example of user-defined integrity rule in database systems?

    - by Pavel
    Hey everyone. I'm currently preparing for my exams and would like to know some examples of user-defined integrity rule in database systems. As far as I understand, it means that I can set up certain conditions for the columns and when data is inserted it needs to fulfill these conditions. For example: if I set up a rule that an ID needs to consist of 5 integers ONLY then when I insert a row with ID which is made up of integers and some chars then it won't accept it and return an error. Could someone confirm and give me some opinion on that? Thank you very much in advance!

    Read the article

  • How to model localized items

    - by tweir
    I'm currently designing a e-commerce solution. One of the primary requirements is for the store to support localized item details. The same store must be able to support multiple languages via the user's language selection and/or browser preference. I have two tables: Item (id, sku, price, ...) ItemDetails (item_id, language, title, ...) For each Item, there will be multiple rows corresponding to the item, where the (item_id,language) pair will be unique. I would like to model this as: class Item { public string sku; public double price; public ItemDetails Details; } Based on the user's session, I would like the items returned to have the Details object corresponds to the user's selected language (from their session). What are some approaches for representing this?

    Read the article

  • Type casting problem with java for-each loop

    - by pharma_joe
    Hi, I have traced an issue with an application I am developing, it is giving me a type cast exception. Funny thing is it is saying it cannot cast "entities.Movie cannot be cast to entities.Movie"?! movies is an ArrayList. try { movies = getMovies(); } catch (Exception e) { e.printStackTrace(System.out); } finally { try { for (Movie movie : movies) { output.append(" <tr>\n"); output.append(" <td>" + movie.getId() + "</td>"); output.append(" </tr>\n"); } } catch (Exception e) { e.printStackTrace(System.out); } }

    Read the article

  • Passing Func<T> to controller constructure when using Unity IoC with MVC, advantages?

    - by user1361315
    I was looking at a sample of how to setup Unity IoC with MVC, and noticed someone who recommended the approach of having the parameters of Func. I believe the advantage is this is kind of like lazy loading the service, if it never gets called it will never get executed and not consume any resources. private readonly Func<IUserService> _userService; public CourseController(Func<IUserService> userService) { this._userService = userService; } Versus a parameter without a Func: private readonly IUserService _userService; public CourseController(IUserService userService) { this._userService = userService; } Can someone explain to me the differences, is it really more effecient?

    Read the article

  • IEnumerator seems to be effecting all objects, and not one at a time

    - by PFranchise
    Hey, I am trying to alter an attribute of an object. I am setting it to the value of that same attribute stored on another table. There is a one to many relationship between the two. The product end is the one and the versions is the many. Right now, both these methods that I have tried have set all the products returned equal to the final version object. So, in this case they are all the same. I am not sure where the issue lies. Here are my two code snipets, both yield the same result. int x = 1 IEnumerator<Product> ie = productQuery.GetEnumerator(); while (ie.MoveNext()) { ie.Current.RSTATE = ie.Current.Versions.First(o => o.VersionNumber == x).RSTATE; x++; } and foreach (var product in productQuery) { product.RSTATE = product.Versions.Single(o => o.VersionNumber == x).RSTATE; x++; } The versions table holds information for previous products, each is distinguished by the version number. I know that it will start at 1 and go until it reaches the current version, based on my query returning the proper number of products. Thanks for any advice.

    Read the article

  • insert with many to many relationship

    - by Luca Romagnoli
    hi, i have 2 object: user, group that have a relationship many to many i want create a user and associate some groups to it. How can i do it? thanks I've tried with this. but it's wrong: user = new User(); List<int> gruppi = new List<int>() {1,2}; utente.Group =db.Group.Where(p => gruppi.Contains(p.GruppoID)

    Read the article

  • EF4 querying through the generations

    - by Hans Kesting
    I have a model withs Parents, Children and Grandchildren, in a many-to-many relationship. Using this article I created POCO classes that work fine, except for one thing I can't yet figure out. When I query the Parents or Children directly using LINQ, the SQL reflects the LINQ query (a .Count() executes a COUNT in the database and so on) - fine. The Parent class has a Children property, to access it's children. But (and now for the problem) this doesn't expose an IQueryable interface but an ICollection. So when I access the Children property on a particular parent all the Parent's Children are read. Even worse, when I access the Grandchildren (theParent.Children.SelectMany(child => child.GrandChildren).Count()) then for each and every child a separate request is issued to select it's grandchildren. Changing the type of the Children property from ICollection to IQueryable doesn't solve this. Apart from missing needed methods like Add() and Remove(), EF just doesn't recognize the property then. Are there correct ways (as in: low database interaction) of querying through children (and what are they)? Or is this just not possible?

    Read the article

  • Can I Use EF Across Multiple DBs in One SQLServer Instance?

    - by thomashubschman
    Hello, I have been searching the blogs and articles but I have not found much support for this scenario. I have been poking around EF and realized that I could create views that contained data from multiple databases and then build the EF object model off of those views. Although it works I am not sure about the usual issues of performance, scalability, maintainability. The way I am achieving the connection between databases is by creating associations in the EF model. Does anyone have any information about this type of implementation? Either another solution or commentary on this proposed solution? Thanks, Tom

    Read the article

  • EntityFramework 4.0: can you return different types depending on data in the database?

    - by user200341
    I have a Media table in the database. I also have an IMedia interface. I have two different media types that implements the same interface: 1) AudioMedia 2) PictureMedia What I wonder here, is if I can use EntityFramework (I'm using an EDMX file but I have my models in a separate library, with automatic code generation turned off), and depending on the data in the database, select what type to get (AutioMedia or PictureMedia). Since they are both implementing the same interface (could be changed to an abstract class if needed I suppose), I'm thinking that somewhere along the way you could specify what class it should be. I should perhaps point out that I have a class that inherits from ObjectContext to access the objects. Perhaps there is something that that can be done?

    Read the article

  • How to: Avoid Inserting Related Entities?

    - by niaher
    I have this schema: I want to insert an Order with OrderItems into database, so I wrote this method: public void SaveOrder(Order order) { using (var repository = new StoreEntities()) { // Add order. repository.Orders.AddObject(order); // Add order items. foreach (OrderItem orderItem in order.OrderItems) { repository.OrderItems.AddObject(orderItem); } repository.SaveChanges(); } } Everything is inserted just fine, except that new Product records are inserted too, which is not what I want. What I want is to insert Order and its OrderItems, without going any further down the object graph. How can that be achieved? Any help is really appreciated, thank you.

    Read the article

  • How to query for entities with no matching siblings, with LINQ?

    - by Ryan
    I've got the two following entities ... class Citation { public int CitationId { get; set; } public string Identifier { get; set; } } class CitationIdentifier { public int CitationIdentifierId { get; set; } public string Identifier { get; set; } } I'm trying to query for all Citation records where the Identifier property does not match any of the CitationIdentifiers record Identifier property. So, if I have a Citation with an Identifier property containing "foo", but there are no CitationIdentifier records with an Identifier property containing "foo", then I'd like to retrieve that Citation. I'm working with an IDbSet<Citation>. Any ideas? Thanks.

    Read the article

  • Disabling identity (auto-incrementing) on integer primary key using code first

    - by gw0
    I am using code first approach in a ASP.NET MVC 3 application and all integer primary keys in models (public int Id { get; set; }) are by default configured as an identity with auto-incrementing. How to disable this and enable a way to manually enter the integer for the primary key? The actual situation is that the Id integers have a special meaning and I would therefore like to have them choosable at creation and later editable. It would be ideal if in case the integer is not given at creation time it is auto-incremented, else the specified value is used. But editable primary fields is my primary need. Is there any way to do this elegantly in ASP.NET MVC 3?

    Read the article

  • ASP.NET check if LinqToEntities returned something or not.

    - by Alex
    How to make this method return boolean value, depending on query return. False - nothing, True - data exists. Before i just returned int from uniqueQuote.Count() but does not look like great method. Thank you! private bool CheckEnquiryUser(int enquiryId, Guid userId) { int selectedEnquiryId = enquiryId; Guid currentUserId = userId; Entities ctx3 = new Entities(); var uniqueQuote = from quot in ctx3.Enquiries.Include("aspnet_Users") where quot.EnquiryId == selectedEnquiryId && quot.aspnet_Users.UserId == currentUserId select quot; bool exist = uniqueQuote; return exist;

    Read the article

  • How can I Include Multiples Tables in my linq to entities eager loading using mvc4 C#

    - by EBENEZER CURVELLO
    I have 6 classes and I try to use linq to Entities to get the SiglaUF information of the last deeper table (in the view - MVC). The problem is I receive the following error: "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection." The view is like that: > @model IEnumerable<DiskPizzaDelivery.Models.EnderecoCliente> > @foreach (var item in Model) { > @Html.DisplayFor(modelItem => item.CEP.Cidade.UF.SiglaUF) > } The query that i use: var cliente = context.Clientes .Include(e => e.Enderecos) .Include(e1 => e1.Enderecos.Select(cep => cep.CEP)) .SingleOrDefault(); The question is: How Can I improve this query to pre loading (eager loading) "Cidade" and "UF"? See below the classes: public partial class Cliente { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int IdCliente { get; set; } public string Email { get; set; } public string Senha { get; set; } public virtual ICollection<EnderecoCliente> Enderecos { get; set; } } public partial class EnderecoCliente { public int IdEndereco { get; set; } public int IdCliente { get; set; } public string CEPEndereco { get; set; } public string Numero { get; set; } public string Complemento { get; set; } public string PontoReferencia { get; set; } public virtual Cliente Cliente { get; set; } public virtual CEP CEP { get; set; } } public partial class CEP { public string CodCep { get; set; } public string Tipo_Logradouro { get; set; } public string Logradouro { get; set; } public string Bairro { get; set; } public int CodigoUF { get; set; } public int CodigoCidade { get; set; } public virtual Cidade Cidade { get; set; } } public partial class Cidade { public int CodigoCidade { get; set; } public string NomeCidade { get; set; } public int CodigoUF { get; set; } public virtual ICollection<CEP> CEPs { get; set; } public virtual UF UF { get; set; } public virtual ICollection<UF> UFs { get; set; } } public partial class UF { public int CodigoUF { get; set; } public string SiglaUF { get; set; } public string NomeUF { get; set; } public int CodigoCidadeCapital { get; set; } public virtual ICollection<Cidade> Cidades { get; set; } public virtual Cidade Cidade { get; set; } } var cliente = context.Clientes .Where(c => c.Email == email) .Where(c => c.Senha == senha) .Include(e => e.Enderecos) .Include(e1 => e1.Enderecos.Select(cep => cep.CEP)) .SingleOrDefault(); Thanks!

    Read the article

  • Entityframework duplicate record on second insert

    - by Delysid
    I am building an application for recipe/meal planning, and i have come across a problem i cant seem to figure out. i have a table for units of measure, where i keep the used units in, i only want unique units in here (for grocery list calculation and so forth) but if i use a unit from the table on a recipe, the first time it is okay, nothing is inserted in units of measure, but the second time i get a "duplicate". i suspect it has something to do with entitykey, because the primary key is identity column on the sql server (2008 r2) for some reason it works to change the objectstate on some objects (courses, see code) and that does not generate a duplicate, but that does not work on the unit of measure my insert methods looks like this : public recipe Create(recipe recipe) { using (RecipeDataContext ctx = new RecipeDataContext()) { foreach (recipe_ingredient rec_ing in recipe.recipe_ingredient) { if (rec_ing.ingredient.ingredient_id == 0) { ingredient ing = (from _ing in ctx.ingredients where _ing.name == rec_ing.ingredient.name select _ing).FirstOrDefault(); if (ing != null) { rec_ing.ingredient_id = ing.ingredient_id; rec_ing.ingredient = null; } } if (rec_ing.unit_of_measure.unit_of_measure_id == 0) { unit_of_measure _uom = (from dbUom in ctx.unit_of_measure where dbUom.unit == rec_ing.unit_of_measure.unit select dbUom).FirstOrDefault(); if (_uom != null) { rec_ing.unit_of_measure_id = _uom.unit_of_measure_id; rec_ing.unit_of_measure = null; } } ctx.Recipes.AddObject(recipe); //for some reason it works to change object state of this, and not generate a duplicate ctx.ObjectStateManager.ChangeObjectState(recipe.courses[0], EntityState.Unchanged); } ctx.SaveChanges(); } return recipe; } My datamodel looks like this : http://i.imgur.com/NMwZv.png

    Read the article

  • EF4 (CPT5) ForeignKeyAttribute in base class - Assert Failure entityType != null

    - by Anthony Johnston
    Getting an error when trying to set a ForeignKeyAttribute in a base class class User{} abstract class FruitBase{ [ForeignKey("CreateById")] public User CreateBy{ get; set; } public int CreateById{ get; set; } } class Banana{} class DataContext : DbContext{ DbSet<Banana> Bananas{ get; set; } } If I move the FruitBase code into the banana, all is well, but I don't want to, as there will be many many fruit and I want to remain relatively DRY if I can Is this a know issue that will be fixed by March? Does anyone know a work around?

    Read the article

  • how to print not mapped value

    - by IcanMakeIt
    I am using complicated SQL queries, i have to use SqlQuery ... in simple way: MODEL: public class C { public int ID { get; set; } [NotMapped] public float Value { get; set; } } CONTROLLER: IEnumerable<C> results = db.C.SqlQuery(@"SELECT ID, ATAN(-45.01) as Value from C); return View(results.ToList()); VIEW: @model IEnumerable<C> @foreach (var item in Model) { @Html.DisplayFor(modelItem => item.Value) } and the result for item.Value is NULL. So my question is , how can i print the computed value from SQL Query ? Thank you for help.

    Read the article

  • EF Query with conditional include that uses Joins

    - by makerofthings7
    This is a follow up to another user's question. I have 5 tables CompanyDetail CompanyContacts FK to CompanyDetail CompanyContactsSecurity FK to CompanyContact UserDetail UserGroupMembership FK to UserDetail How do I return all companies and include the contacts in the same query? I would like to include companies that contain zero contacts. Companies have a 1 to many association to Contacts, however not every user is permitted to see every Contact. My goal is to get a list of every Company regardless of the count of Contacts, but include contact data. Right now I have this working query: var userGroupsQueryable = _entities.UserGroupMembership .Where(ug => ug.UserID == UserID) .Select(a => a.GroupMembership); var contactsGroupsQueryable = _entities.CompanyContactsSecurity;//.Where(c => c.CompanyID == companyID); /// OLD Query that shows permitted contacts /// ... I want to "use this query inside "listOfCompany" /// //var permittedContacts= from c in userGroupsQueryable //join p in contactsGroupsQueryable on c equals p.GroupID //select p; However this is inefficient when I need to get all contacts for all companies, since I use a For..Each loop and query each company individually and update my viewmodel. Question: How do I shoehorn the permittedContacts variable above and insert that into this query: var listOfCompany = from company in _entities.CompanyDetail.Include("CompanyContacts").Include("CompanyContactsSecurity") where company.CompanyContacts.Any( // Insert Query here.... // b => b.CompanyContactsSecurity.Join(/*inner*/,/*OuterKey*/,/*innerKey*/,/*ResultSelector*/) ) select company; My attempt at doing this resulted in: var listOfCompany = from company in _entities.CompanyDetail.Include("CompanyContacts").Include("CompanyContactsSecurity") where company.CompanyContacts.Any( // This is concept only... doesn't work... from grps in userGroupsQueryable join p in company.CompanyContactsSecurity on grps equals p.GroupID select p ) select company;

    Read the article

  • EF Linq Product Sum when no records returned

    - by user1622713
    I’ve seen variations of this question all over the place but none of the answers work for me. Most of them are just trying to sum a single column too – nothing more complex such as the sum of a product as below: public double Total { get { return _Context.Sales.Where(t => t.Quantity > 0) .DefaultIfEmpty() .Sum(t => t.Quantity * t.Price); } } If no rows are returned I want to return zero. However if no rows are returned the .Sum() fails. There are various options of trying to insert Convert.ToDouble and using null coalesce operators, but they all still gave me errors. I’m sure I am missing a simple way to do this – any help greatly appreciated after too long banging head against google brick wall!

    Read the article

< Previous Page | 104 105 106 107 108 109 110 111 112 113 114 115  | Next Page >