{"Invalid specified type from materialized type" System.Guid "to type" System.Int32 ".

I have an Entity structure model that contains one asset table as follows:

public partial class Asset
{
    public int Switch { get; set; }
    public string Port { get; set; }
    public string Name { get; set; }
    public string Connection { get; set; }
    public string Interface { get; set; }
    public string ConnectionUser { get; set; }
    public string ConnectionDate { get; set; }
}

I am trying to return the column "Name". This is the code I use for this:

    // create the entity model for DB operations
    acls3Entities entities = new acls3Entities();
    List<Asset> assets = entities.Assets.ToList();

    foreach (Asset asset in assets)
    {
        Console.WriteLine(string.Format("{0}", asset.Name));
    };

However, it gives me the error mentioned in the header of this post in a line that defines “assets”. How can I solve this problem?

+4
source share
2 answers

GUID is not int, in your database, Switch is GUID.

GUID is a hexadecimal number divided by

Here are three GUID examples:

839E4FB1-F5F5-4C46-AFD1-000002CC625F

06F6D8BA-C10D-4806-B190-000006BA0513

2D3343FD-3E8A-4B33-9198-00002031F5F8

int , -

, :

public partial class Asset
{
public Guid Switch { get; set; }  // here <- GUID
public string Port { get; set; }
public string Name { get; set; }
public string Connection { get; set; }
public string Interface { get; set; }
public string ConnectionUser { get; set; }
public string ConnectionDate { get; set; }
}

, edmx , , , .

:

  • .edmx (, , acls3Entities.edmx)

  • ... ? , , .

  • - Update from database - ( ...)

  • // , ,

+5

I solved this problem by using ToString() .

:

Guid userId = Guid.Parse(User.Identity.GetUserId());    
candidateDashBoard.DismissalRecord = db.DismissalRecords.Where(c => 
                  c.CandidateId == userId).FirstOrDefault();

:

Guid userId = Guid.Parse(User.Identity.GetUserId());
candidateDashBoard.DismissalRecord = db.DismissalRecords.Where(c => 
                  c.CandidateId.ToString() == userId.ToString()).FirstOrDefault();
0

All Articles