Mapping issue

Posts   
 
    
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 22-Feb-2012 16:06:30   

Hi There,

I am trying to run the trial version just to do some preliminary testing as we are intended to buy this tool. I created LINQ to SQL code and it is giving me following error. What is the possibility to fix this?

View the attachment.

Attachments
Filename File size Added on Approval
notmapped.gif 94,546 22-Feb-2012 16:06.49 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2012 17:49:30   

The error says the entity used is not mapped into a database table. Could you please check the mappings in the mappoing tab in the properties of the entity, in the Designer.

Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 22-Feb-2012 18:15:11   

Walaa wrote:

The error says the entity used is not mapped into a database table. Could you please check the mappings in the mappoing tab in the properties of the entity, in the Designer.

TAB "Fields mapped onto related fields" has no field. Its empty.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2012 18:26:09   

SO it had the mappings set at a point f time, then they disappear? Can you say at what action they disappeared?

Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 22-Feb-2012 18:38:39   

Walaa wrote:

SO it had the mappings set at a point f time, then they disappear? Can you say at what action they disappeared?

I tell you, this is first time i am using LLBLGEN. I am not very much sure about anything. I created project LINQ To SQL. Added relational model data i.e Northwind. I right clicked on Nortwind database in catalog explorer and clicked on Reverse-Engineer Tables to Entity Definitions. Validate and generate code. I created one solution with one website in it. Added the project created by LLBLGEN. All that stuff of referencing is done. When wrote one piece of code which is pulling product name from product table and it gives the error you are looking at.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2012 18:53:03   

Please attach the llblgen pro, or better a a repro.

Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 22-Feb-2012 18:53:56   

Walaa wrote:

Please attach the llblgen pro, or better a a repro.

Sorry i didn't get what you are asking for?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Feb-2012 06:02:44   

Qurban wrote:

Walaa wrote:

Please attach the llblgen pro, or better a a repro.

Sorry i didn't get what you are asking for?

Walaa meant: the .llblgenproj file, the LLBLGen project file, attach it so we can figure this out.

David Elizondo | LLBLGen Support Team
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 23-Feb-2012 10:51:57   

daelmo wrote:

Qurban wrote:

Walaa wrote:

Please attach the llblgen pro, or better a a repro.

Sorry i didn't get what you are asking for?

Walaa meant: the .llblgenproj file, the LLBLGen project file, attach it so we can figure this out.

Qurban wrote:

I created project LINQ To SQL. Added relational model data i.e Northwind. I right clicked on Nortwind database in catalog explorer and clicked on Reverse-Engineer Tables to Entity Definitions. Validate and generate code. I created one solution with one website in it. Added the project created by LLBLGEN. All that stuff of referencing is done. When wrote one piece of code which is pulling product name from product table and it gives the error you are looking at.

Attach zip contains, VS solution, website and LLBLGEN created project and LLBLProject as well.

Attachments
Filename File size Added on Approval
LLBLGen.rar 288,761 23-Feb-2012 10:52.17 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Feb-2012 11:17:34   

Please check this out: Using an Xml Mapping File

So for you attached repro, you should do the following:

var modelAssembly = typeof(LLBLGenNorthwindDataContext).Assembly;
var resourceStream =
    modelAssembly.GetManifestResourceStream("LLBLGenNorthwind.LLBLGenNorthwindMappings.xml");
var ctx = new LLBLGenNorthwindDataContext(XmlMappingSource.FromStream(resourceStream));

//LLBLGenNorthwindDataContext db = new LLBLGenNorthwindDataContext();
var products = from p in ctx.Products                   
               select p;
GridView1.DataSource = products;
GridView1.DataBind();
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 23-Feb-2012 11:20:43   

Walaa wrote:

Please check this out: Using an Xml Mapping File

So for you attached repro, you should do the following:

var modelAssembly = typeof(LLBLGenNorthwindDataContext).Assembly;
var resourceStream =
    modelAssembly.GetManifestResourceStream("LLBLGenNorthwind.LLBLGenNorthwindMappings.xml");
var ctx = new LLBLGenNorthwindDataContext(XmlMappingSource.FromStream(resourceStream));

//LLBLGenNorthwindDataContext db = new LLBLGenNorthwindDataContext();
var products = from p in ctx.Products                   
               select p;
GridView1.DataSource = products;
GridView1.DataBind();

I already tried the solution you mentioned from this thread http://llblgen.com/tinyforum/Messages.aspx?ThreadID=19367 but i get the error attached.

EDITED: Also if you could please let me know what is the other option like if i don't use xml mapping option? Also what is recommended? using xml mapping or not?

Attachments
Filename File size Added on Approval
llblgenxml.gif 143,634 23-Feb-2012 11:21.01 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Feb-2012 11:24:34   

I'm not sure I understand you. If you generate the mappings to an XML file, you have to use the code I've posted, I tried it in your repro and it works, and the grid displays the data without an error.

Whether to use an xml mappings or not, I'm not sure which is better, but I think it doesn't make any difference at runtime.

Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 23-Feb-2012 11:25:50   

Walaa wrote:

I'm not sure I understand you. If you generate the mappings to an XML file, you have to use the code I've posted, I tried it in your repro and it works, and the grid displays the data without an error.

Whether to use an xml mappings or not, I'm not sure which is better, but I think it doesn't make any difference at runtime.

Really!!! but on my side it says "System.Data.SqlClient.SqlException: Invalid object name 'dbo.Products'."

Its really weired.

I enabled the debug option and its gives the error on binding;

nvalid object name 'dbo.Products'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Products'.

Source Error:

Line 20: select p; Line 21: GridView1.DataSource = products; Line 22: GridView1.DataBind(); Line 23: } Line 24: }

Source File: c:\Projects\TestProjects\LLBGenTest\LLBLGen\WebSite1\Default.aspx.cs Line: 22

Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 23-Feb-2012 13:39:47   

Walaa wrote:

I'm not sure I understand you. If you generate the mappings to an XML file, you have to use the code I've posted, I tried it in your repro and it works, and the grid displays the data without an error.

Whether to use an xml mappings or not, I'm not sure which is better, but I think it doesn't make any difference at runtime.

Just to see the difference, i just created one LINQ to SQL project in VS 2010 and attached the data model of northiwnd and tested. It works. The only difference i could see is that before the class starts the following line is mentioned.

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Products")]

whereas this is not in the LLBLGEN generated project. I added this line and it doesn't produce any positive result.

Qurban

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 23-Feb-2012 20:30:29   

Your connection string points to a different DB I think. Make sure the connection string points to the right DB/server, as the table isn't found in the database you're connecting to.

Frans Bouma | Lead developer LLBLGen Pro
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 24-Feb-2012 10:49:25   

Otis wrote:

Your connection string points to a different DB I think. Make sure the connection string points to the right DB/server, as the table isn't found in the database you're connecting to.

thanks. this was what i was missing... thanks