Entity Error in GDataDB example - c#

Im getting the error "the type or namespace name 'Entity' could not be found" from the following code snippet.
So ive added the reference "System.Data.Entity" but its still not working...
Why is that?
Error 1 The type or namespace name 'Entity' could not be found (are you missing a using directive or an assembly reference?)...
using System;
using System.Linq;
using GDataDB;
using GDataDB.Linq;
using System.Data.Entity;
....
Console.WriteLine("Connecting");
var client = new DatabaseClient("you#gmail.com", "password");
const string dbName = "testing";
Console.WriteLine("Opening or creating database");
var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
const string tableName = "testtable";
Console.WriteLine("Opening or creating table");
var t = db.GetTable<Entity>(tableName) ?? db.CreateTable<Entity>(tableName);
Console.WriteLine("Feed url for this table is '{0}'", t.GetFeedUrl());
var all = t.FindAll();
Console.WriteLine("{0} elements", all.Count);
....

There is no using System.Data.Entity; in the GDataDB sample app, and never has been, so either you or some automated tool added it.
So simply remove it.
If you're missing the Entity type, make sure you get the whole sample project and not just Program.cs
GDataDB has no relationship to EF or LINQ-to-SQL at all.

Related

Creating a script with List

I'm attempting to create a script with Microsoft.CodeAnalysis.CSharp.Scripting.
As soon as I add List<> the code errors. I thought I had all the necessary references and usings included, however it still errors stating The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?
These are my usings in the code
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
Below is my example unit test
[TestMethod]
public void RunGenericListTest()
{
var code = #"
List<string> strings = new List<string>();
strings.Add(""test string"");
return output;";
var options = ScriptOptions.Default;
options.WithReferences(typeof(System.Collections.CollectionBase).Assembly);
options.WithReferences(typeof(System.Collections.Generic.List<>).Assembly);
options.WithImports("System.Collections");
options.WithImports("System.Collections.Generic");
var result = CSharpScript.RunAsync(code, options).Result;
Debug.WriteLine(result);
}
This errors on the CSharpScript.RunAsync every time. Can someone enlighten me on what I'm missing?
I think the issue is, WithImports does not mutate options but rather returns a copy
var code = #"
List<string> strings = new List<string>();
strings.Add(""test string"");
return strings;";
var options = ScriptOptions.Default
.WithImports("System.Collections.Generic"); // chaining methods would work better here.
// alternatively reassign the variable:
// options = options.WithImports("System.Collections.Generic");
var result = CSharpScript.RunAsync(code, options).Result;
Debug.WriteLine((result.ReturnValue as List<string>).First());

What reference should I use for 'Data.ValueRange'?

I'm following a guide to write output data from Visual Studio into a google spreadsheet.
At the end of the guide there is a code block that I pasted inside my project:
using OpenQA.Selenium.Support.UI;
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Collections;
using System.Collections.Generic;
using Google.Apis.Sheets.v4;
using Google.Apis.Auth.OAuth2;
using System.IO;
using Google.Apis.Services;
using Newtonsoft.Json;
using WikipediaTests.Foundation_Class;
using System.Web;
using System.Data;
using Google.Apis.Sheets.v4.Data;
namespace AutomationProjects
{
[TestFixture]
public class TestClass : TestFoundation
{
public class SpreadSheetConnector
{
//Codeblock from guide pasted here!
}
[Test]
public void test1()
{
//Test case 1. Do XYZ...
}
}
}
In the code block included in the guide there is a section about creating a list and passing data into it:
// Pass in your data as a list of a list (2-D lists are equivalent to the 2-D spreadsheet structure)
public string UpdateData(List<IList<object>> data)
{
String range = "My Tab Name!A1:Y";
string valueInputOption = "USER_ENTERED";
// The new values to apply to the spreadsheet.
List<Data.ValueRange> updateData = new List<Data.ValueRange>();
var dataValueRange = new Data.ValueRange();
dataValueRange.Range = range;
dataValueRange.Values = data;
updateData.Add(dataValueRange);
Data.BatchUpdateValuesRequest requestBody = new Data.BatchUpdateValuesRequest();
requestBody.ValueInputOption = valueInputOption;
requestBody.Data = updateData;
var request = _sheetsService.Spreadsheets.Values.BatchUpdate(requestBody, _spreadsheetId);
Data.BatchUpdateValuesResponse response = request.Execute();
// Data.BatchUpdateValuesResponse response = await request.ExecuteAsync(); // For async
return JsonConvert.SerializeObject(response);
}
The problem is that I get an error for the 'Data.ValueRange' and the 'Data.BatchUpdateValuesRequest' :
CS0246 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)
I tried adding "System.Data" as a assembly reference to my project and then added it at the top (using). But it did not remove the error.
'Data.' seems to belong to "Google.Apis.Sheets.v4" but I have already added that reference as the guide instructed.
The only fix that gets rid of the error is adding Google.Apis.Sheets.v4 before every 'Data.' like this:
List<Google.Apis.Sheets.v4.Data.ValueRange>
But when I run my tests the output does not get exported to my spreadsheet. So I'm assuming this is not the correct solution. And also I'm assuming that the guide should have included this in the code block if it was necessary.
Could there be some other reference about 'Data' I need?
According to the documentation, the ValueRange Class depends of Sheets.v4.Data, so you should add:
using Google.Apis.Sheets.v4.Data;
Also, change:
List<Data.ValueRange> updateData = new List<Data.ValueRange>();
to:
List<ValueRange> updateData = new List<ValueRange>();

fakeXrmEasy for crm testing initialization issues

I'm trying to follow the basic tutorial for FakeXrmEasy, but I'm not sure why I'm getting errors. I installed everything that needs to be installed to mock Dynamics 365, but I'm still getting errors. I can't figure out what I'm missing, I really want to be able to use this tool.
CS1950 The best overloaded Add method 'List.Add(Entity)' for the collection initializer has some invalid arguments unitTest c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 48 Active
CS0246 The type or namespace name 'Account' could not be found (are you missing a using directive or an assembly reference?) unitTest c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 45 Active
Didn't know if I was suppose to create an account class, I also tried that but that didn't work either. I got
CS1503 Argument 1: cannot convert from 'unitTest.Account' to 'Microsoft.Xrm.Sdk.Entity' unitTest c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 48 Active
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FakeItEasy;
using FakeXrmEasy;
using Microsoft.Xrm.Sdk;
namespace unitTest
{
class Program
{
static void Main(string[] args)
{
}
}
class unitTest
{
public object ProxyTypesAssembly { get; private set; }
public void MyFirstTest()
{//test method body
var context = new XrmFakedContext();
//You can think of a context like an Organisation database which stores entities In Memory.
//We can also use TypedEntities but we need to tell the context where to look for them,
//this could be done, easily, like this:
context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));
//We have to define our initial state now,
//by calling the Initialize method, which expects a list of entities.
var account = new Account() { Id = Guid.NewGuid(), Name = "My First Faked Account yeah!" };
context.Initialize(new List<Entity>() {
account
});
}
}
}
Do you use early binding in your CRM project and got the references right? If you do not use early binding, you can try late binding, e.g.
//context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));
var account = new Entity();
account.LogicalName = "account";
account.Attributes["name"] = "your account name";

Can't reference Regex in string extension method

I have run into very strange problem:
I have made extension method for string like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Vaniv.Mvc
{
public static class StringHelpers
{
public static string ToSeoUrl(this string url)
{
// make the url lowercase
string encodedUrl = (url ?? "").ToLower();
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 -]");
encodedUrl = rgx.Replace(encodedUrl, "-");
return encodedUrl;
}
}
}
And problem that durning runstime I get error:
CS0246: The type or namespace name 'Regex' could not be found (are you missing a using directive or an assembly reference?)
Im not missing using directive. Nor do I missing Assembly (I can use Regex withing controller for example).
I have put my extension method into App_Code, but doubt it have any connection,
Move the cs file to another directory (out of App_Code folder) put it on the root of the project.
Check this article

what namespaces used to remove the following errors?

my question is that if the user click on button(which is placed in default.aspx,for example) then the database table is created in database(database is placed in sql express 2005)how can do ?.
I try this task by another method but the following errors are occurred:
1.'system.Web.UI.Page.Server' is a 'property' but is used like a 'type'.
2.The type or namespace name 'Database' could not be found(are you
missing a using directive or an
assembly reference?)
3.The name 'DataType' does not exist in the current context.
4.'System.Web.UI.WebControls.Table' does not contain a definition for
'columns' and no extension method
'columns' accepting a first argument
of type
'System.Web.UI.WebControls.Table' could be found(are you missing a using
directive or an assembly reference.
5.'System.Data.Index' is inaccessible due to its protection
level.
6.'System.Data.Index' does not contain a constructor that takes '2'
arguments.
7.'System.Data.Index' does not contain a definition for
'IndexKeyType' and no extension method
'IndexKeyType' accepting a first
argument of type 'System.Data.Index'
could be found(are you missing a using
directive or an assembly reference?)
8.The name 'IndexKeyType' does not exist in the current context.
9.'System.Data.Index' does not contain a definition
for'IndexedColumns' and no extension
method 'IndexedColumns' accepting a
first argument of type
'System.Data.Index' could be found(are
you missing a using directive or
assembly reference?)
10.The type or namespace name 'Indexedcolumn' could not be found(are
you missing a using directive or an
assembly reference?)
11.'System.Web.UI.WebControls.Table' does not contain a definition for
'Indexes' and no extension method
'Indexes' accepting a first argument
of type
'System.Web.UI.Webcontrols.Table'
could be found(are you missing a using
directive or an assembly reference?)
13.'System.Web.UI.WebControls.Table' does not Contain a definition for
'Create' and no extension method
'Create' accepting a first argument of
type 'Systen.Web.UI.WebControls.Table'
could be found(are you missing a using
directive or an assembly reference?)
The code written in c# behind the button is that:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
//using System.Data.OleDb;
using System.Diagnostics;
using System.ComponentModel;
using System.Text;
using System.Data.SqlClient;
//using System.Data.Odbc;
using Microsoft.SqlServer.Management.Common;
//using ADOX;
//using ADODB;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// Establish the database server
string connectionString = ConfigurationManager.ConnectionStrings["gameConnectionString"].ConnectionString;
SqlConnection connection =
new SqlConnection(connectionString);
Server server =
new Server(new ServerConnection(connection));
// Create table in my personal database
Database db = server.Databases["game"];
// Create new table, called TestTable
Table newTable = new Table(db, "TestTable");
// Add "ID" Column, which will be PK
Column idColumn = new Column(newTable, "ID");
idColumn.DataType = DataType.Int;
idColumn.Nullable = false;
idColumn.Identity = true;
idColumn.IdentitySeed = 1;
idColumn.IdentityIncrement = 1;
// Add "Title" Column
Column titleColumn = new Column(newTable, "Title");
titleColumn.DataType = DataType.VarChar(50);
titleColumn.Nullable = false;
// Add Columns to Table Object
newTable.Columns.Add(idColumn);
newTable.Columns.Add(titleColumn);
// Create a PK Index for the table
Index index = new Index(newTable, "PK_TestTable");
index.IndexKeyType = IndexKeyType.DriPrimaryKey;
// The PK index will consist of 1 column, "ID"
index.IndexedColumns.Add(new IndexedColumn(index, "ID"));
// Add the new index to the table.
newTable.Indexes.Add(index);
// Physically create the table in the database
newTable.Create();
}
}
sir please solve these errors and also give the solution in detail through which i can easily understand.I am very confused in this task please help me.Thank sir
Suggest abandoning your current approach. The problems go beyond namespacing. Suggest taking these steps:
create a brand new test project for the following
determine the SQL statements for
creating a table with all columns
creating the index
execute the SQL statements above using ADO.NET. Suggest a SqlConnection and SqlCommand.
Something like this:
using (var conn = new SqlConnection(connString))
{
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = createTableStatement; //CREATE TABLE Foo (ID int);
conn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = createIndexStatement;
cmd.ExecuteNonQuery();
}
}
This will get you started on accomplishing your task. Be sure that any user-entered data aren't simply placed into your strings to create your objects. If so, change the approach to use parameters with your SqlCommand.
Here's an article on Beginner's Guide to Accessing SQL Server Through C#

Categories

Resources