Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DeanShea · Jun 29, 2018 at 08:40 AM · linq

Can not convert lamda expression to non delegate type

I am getting the error Assets/Resources/Scripts/Database/Database.cs(27,31): error CS1660: Cannot convert lambda expression' to non-delegate type System.Linq.Expressions.Expression>' in the unity console but I am not receiving the same error in visual studio.

My Code is

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using System.Data.Common;
 using Microsoft.EntityFrameworkCore;
 using Npgsql.EntityFrameworkCore;
 using Npgsql;
 using System.Linq;
 
     public class DatabaseManager : DbContext
     {
         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
             optionsBuilder.UseNpgsql(@"Host=localhost;Database=entitycore;Username=Chevauchee;Password=Chevauchee");
         }
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
             base.OnModelCreating(modelBuilder);
             modelBuilder.Entity<TileProperty>(entity =>
             {
                 entity.ToTable("Tile");
                 entity.HasKey(e => e.x); //error occours here
                 entity.Property(e => e.y).IsRequired().HasColumnName("y"); //and here
                 entity.Property(e => e.terrain).IsRequired().HasColumnName("terrain"); //and here
                 entity.Property(e => e.domain).IsRequired().HasColumnName("domain"); //and here
             });
         }
         public DbSet<TileProperty> Tile { get; set; }
     }

Any advice would be appreciated

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harinezumi · Jun 29, 2018 at 09:08 AM 1
Share

Unity uses a custom .Net framework that is equivalent to an older version (3.5, if I'm not mistaken), in which features of newer versions (that Visual Studio automatically uses) are not available, and that's why VS is not showing it as an error, but when Unity compiles it, it is.

However, these features are often only "syntactic sugar", that is simpler ways of writing something more complex, or they can be written in a different way. I am not proficient with Linq, but I think if you separate it into several steps, it might work.

Also, in Unity 2017.x an experimental version was introduced, which should be equivalent to .Net 4.6. You can switch to it in Edit -> Project Settings -> Player, and in Other settings scroll down to Configuration, and there use the first option, "Scripting Runtime Version".

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jun 29, 2018 at 09:18 AM

When you use frameworks which are not part of Unity you should read the documentation carefully. I have never used the entity framework of MS but a quick google seach for the ModelBuilder showed that the "Entity" method returns an EntityTypeBuilder object. If you search for the signature of the HasKey method you will notice that it doesn't take a delegate as parameter but a simple params string array


HasKey(String[])

Sets the properties that make up the primary key for this entity type.

public virtual KeyBuilder HasKey(params string[] propertyNames)

Parameters

propertyNames

  System.String[] 

The names of the properties that make up the primary key.

Returns

KeyBuilder

An object that can be used to configure the primary key.


Likewise the Property method takes a single string value as parameter.


Furthermore the PropertyBuilder that is returned by the Property method (and carried on by the IsRequired method) does not have a HasColumnName method. Maybe this was added by another framework you use that is build on top of the MS framework.


However this question is not related to Unity at all and is lacking substantial information like framework versions, which frameworks you're using, etc... Since you already work with those frameworks you should have receive some sort of documentary which you should consult first.


Apart from that it probably should look something like that:

      modelBuilder.Entity<TileProperty>(entity =>
      {
          entity.ToTable("Tile");
          entity.HasKey("x");
          entity.Property("y").IsRequired().HasColumnName("y");
          entity.Property("terrain").IsRequired().HasColumnName("terrain");
          entity.Property("domain").IsRequired().HasColumnName("domain");
      });

As i said i don't know if the HasColumnName exists in your case. If not you may just want to remove it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeanShea · Jul 01, 2018 at 07:15 AM 0
Share

alt text Thanks, for the help your solution worked. I believed it was an issue with unity because I received the following errors in the console but not in the IDE as shown above which I thought was odd

lamdaexpressions.jpg (69.8 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How To Store and Act on Get Component Result in Linq Query? 1 Answer

How to return the first Texture from a List given a texture name (string) using Linq? 1 Answer

Linq List to Gui 0 Answers

C#, LINQ and Lists - help with 1 line of code? 1 Answer

Destroy a gameobject referenced in list and remove that element 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges